Project

General

Profile

Actions

Bug #1868

closed

ERB single line comment does not work

Added by jfahrenkrug (Johannes Fahrenkrug) almost 13 years ago. Updated about 5 years ago.

Status:
Rejected
Priority:
Normal
Target version:
-
ruby -v:
ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
Backport:
[ruby-core:24715]

Description

=begin
Hi,

I just ran into this and found that a 1.9 bug for this is open already. But this issue also applies to 1.8.7. So I'm duplicating the description from here: http://redmine.ruby-lang.org/issues/show/1559

In erb you're supposed to be able to do single line comments:

<% # this is a comment %>

However, this does not work in ruby 1.9.1.

Temporary work around is to put the '%>' on a newline:

<% # this comment works in 1.9.1
%>

Please see attached unit test.
=end


Files

test_erb.rb (313 Bytes) test_erb.rb test that passes in Ruby 1.8.6 but fails in Ruby 1.8.7 jfahrenkrug (Johannes Fahrenkrug), 08/03/2009 08:32 PM

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #14243: Comments inside ERB tags brokenClosedk0kubun (Takashi Kokubun)Actions
Actions #1

Updated by bitsweat (Jeremy Daer) almost 13 years ago

=begin
This is not a bug. Use <# for erb comments.
=end

Actions #2

Updated by rsalkeld (Robin Salkeld) about 12 years ago

=begin
This seems to be caused by removing \n from the regular expressions used in ERB::Compiler::SimpleScanner2:

stag_reg = /(.?)(<%%|<%=|<%#|<%|\z)/m
etag_reg = /(.
?)(%%>|%>|\z)/m

It looks like the original change was intended as an optimization, but unintentionally changed the behaviour. Restoring the \n's fixes it.

<%# may work for comments as well, but a lot of us have relied on the old behaviour, and I see no reason not to fix an accidental regression.
=end

Actions #3

Updated by bitsweat (Jeremy Daer) about 12 years ago

=begin
One reason not to restore the bug: it would break in any other conformant eRuby implementation, like Erubis.
=end

Actions #4

Updated by coatl (caleb clausen) about 12 years ago

=begin
Aside from compatibility with other implementations, what is harmed by making the suggested change? Would it break something that currently works? (I would expect that any legal ruby should be usable inside <%...%>, myself...)
=end

Actions #5

Updated by shyouhei (Shyouhei Urabe) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to seki (Masatoshi Seki)

=begin

=end

Actions #6

Updated by hsbt (Hiroshi SHIBATA) over 7 years ago

  • Project changed from Ruby 1.8 to Ruby master
  • Description updated (diff)

Updated by k0kubun (Takashi Kokubun) about 5 years ago

  • Assignee changed from seki (Masatoshi Seki) to k0kubun (Takashi Kokubun)
  • Status changed from Assigned to Rejected

Supporting this kind of behavior doesn't make sense to me. Suppose following erb template:

foo <% # comment1 %> bar <% # comment2 %> baz

If such a feature is supported, I would expect this template to render "foo bar baz". But since " # comment1 " and " # comment2 " are embedded as Ruby script, concatenation for " bar ", " baz " and "\n" will be regarded as comment. And it's inevitable because we should keep erb's line numbers in generated code for correct backtrace.

In that situation, if we really want to support this, we need to trim comments when compiling erb by scanning all embedded Ruby scripts using Ripper or something. I don't think it's a consistent behavior considering embedded scripts are originally evaluated only on rendering. And it will have performance regression for compiling time. So the most reasonable way to achieve such single-line comment is just using "<%#".

As https://bugs.ruby-lang.org/issues/1559 is rejected and I think it's reasonable, we need to fix all "<% #" to "<%#". Sorry for your inconvenience by regression.

Actions #8

Updated by k0kubun (Takashi Kokubun) over 4 years ago

  • Has duplicate Bug #14243: Comments inside ERB tags broken added
Actions

Also available in: Atom PDF