Skip to content

Commit 05e415c

Browse files
committedFeb 18, 2018
Fixes #5052. String literal difference from MRI.
Basic gist of fix is to push '#' onto result buffer if we did not find any useful characters after the next significant character ('@', '$'). Fixing this was confusing because we have an ancient outdated pushback(char) method which actually ignores c (except for eof).
1 parent 0b06b48 commit 05e415c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎core/src/main/java/org/jruby/lexer/yacc/StringTerm.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ private int parsePeekVariableName(RubyLexer lexer) throws IOException {
147147
lexer.commandStart = true;
148148
return Tokens.tSTRING_DBEG;
149149
default:
150-
// We did not find significant char after # so push it back to
151-
// be processed as an ordinary string.
152-
lexer.pushback(c);
153150
return 0;
154151
}
155152

153+
// We found #@, #$, #@@ but we don't know what at this point (check for valid chars).
156154
if (significant != -1 && Character.isAlphabetic(significant) || significant == '_') {
157155
lexer.pushback(c);
158156
lexer.setValue("#" + significant);
@@ -191,8 +189,10 @@ public int parseString(RubyLexer lexer) throws IOException {
191189
int token = parsePeekVariableName(lexer);
192190

193191
if (token != 0) return token;
192+
193+
buffer.append('#'); // not an expansion to variable so it is just a literal.
194194
}
195-
lexer.pushback(c);
195+
lexer.pushback(c); // pushback API is deceptive here...we are just pushing index back one and not pushing c back necessarily.
196196

197197
Encoding enc[] = new Encoding[1];
198198
enc[0] = lexer.getEncoding();

0 commit comments

Comments
 (0)
Please sign in to comment.