Skip to content

Commit

Permalink
Fixes #1700. NPE in Ripper with $ special variables
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Sep 11, 2014
1 parent 2281c70 commit 8737eb5
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions ext/ripper/src/main/java/org/jruby/ext/ripper/RipperLexer.java
Expand Up @@ -1838,7 +1838,8 @@ private int dollar() throws IOException {
case '<': /* $<: reading filename */
case '>': /* $>: default output handle */
case '\"': /* $": already loaded files */
yaccValue = new Token("$" + (char) c, Tokens.tGVAR);
identValue = "$" + (char) c;
yaccValue = new Token(identValue, Tokens.tGVAR);
return Tokens.tGVAR;

case '-':
Expand All @@ -1851,7 +1852,8 @@ private int dollar() throws IOException {
} else {
pushback(c);
}
yaccValue = new Token(tokenBuffer.toString(), Tokens.tGVAR);
identValue = tokenBuffer.toString();
yaccValue = new Token(identValue, Tokens.tGVAR);
/* xxx shouldn't check if valid option variable */
return Tokens.tGVAR;

Expand All @@ -1860,7 +1862,8 @@ private int dollar() throws IOException {
case '\'': /* $': string after last match */
case '+': /* $+: string matches last paren. */
// Explicit reference to these vars as symbols...
yaccValue = new Token("$" + (char) c);
identValue = "$" + (char) c;
yaccValue = new Token(identValue);
if (last_state == LexState.EXPR_FNAME) return Tokens.tGVAR;

return Tokens.tBACK_REF;
Expand All @@ -1874,11 +1877,13 @@ private int dollar() throws IOException {
} while (Character.isDigit(c));
pushback(c);
if (last_state == LexState.EXPR_FNAME) {
yaccValue = new Token(tokenBuffer.toString(), Tokens.tGVAR);
identValue = tokenBuffer.toString();
yaccValue = new Token(identValue, Tokens.tGVAR);
return Tokens.tGVAR;
}

yaccValue = new Token(tokenBuffer.toString());

identValue = tokenBuffer.toString();
yaccValue = new Token(identValue);
return Tokens.tNTH_REF;
case '0':
setState(LexState.EXPR_END);
Expand Down Expand Up @@ -2009,7 +2014,8 @@ private int identifier(int c, boolean commandState) throws IOException {
int c2 = nextc();
if (c2 == ':' && !peek(':')) {
setState(LexState.EXPR_BEG);
yaccValue = new Token(tempVal + ':');
identValue = tempVal + ':';
yaccValue = new Token(identValue);
return Tokens.tLABEL;
}
pushback(c2);
Expand All @@ -2027,7 +2033,8 @@ private int identifier(int c, boolean commandState) throws IOException {
setState(keyword.state);
}
if (state == LexState.EXPR_FNAME) {
yaccValue = new Token(keyword.name);
identValue = keyword.name;
yaccValue = new Token(identValue);
} else {
yaccValue = new Token(tempVal);
if (keyword.id0 == Tokens.kDO) return doKeyword(state);
Expand Down

0 comments on commit 8737eb5

Please sign in to comment.