Skip to content

Commit

Permalink
Fixes #5052. String literal difference from MRI.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
enebo committed Feb 18, 2018
1 parent 0b06b48 commit 05e415c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/lexer/yacc/StringTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,10 @@ private int parsePeekVariableName(RubyLexer lexer) throws IOException {
lexer.commandStart = true;
return Tokens.tSTRING_DBEG;
default:
// We did not find significant char after # so push it back to
// be processed as an ordinary string.
lexer.pushback(c);
return 0;
}

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

if (token != 0) return token;

buffer.append('#'); // not an expansion to variable so it is just a literal.
}
lexer.pushback(c);
lexer.pushback(c); // pushback API is deceptive here...we are just pushing index back one and not pushing c back necessarily.

Encoding enc[] = new Encoding[1];
enc[0] = lexer.getEncoding();
Expand Down

0 comments on commit 05e415c

Please sign in to comment.