Skip to content

Commit

Permalink
Merge pull request #74 from arthurscchan/fix-invalid-char
Browse files Browse the repository at this point in the history
Fix invalid character handling
  • Loading branch information
enebo authored Aug 4, 2023
2 parents 6a0d556 + c13a66a commit 4fdf926
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/org/joni/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.joni.Option.isWordBoundAllRange;
import static org.joni.ast.QuantifierNode.isRepeatInfinite;

import org.jcodings.Encoding;
import org.jcodings.Ptr;
import org.jcodings.constants.CharacterType;
import org.jcodings.exception.CharacterPropertyException;
Expand Down Expand Up @@ -1174,7 +1175,12 @@ protected final void fetchToken() {
token.type = TokenType.CODE_POINT;
token.setCode(c);
} else { /* string */
p = token.backP + enc.length(bytes, token.backP, stop);
int encLength = enc.length(bytes, token.backP, stop);
/* Check and ensure the encoded character is valid */
if (encLength == Encoding.CHAR_INVALID) {
throw new IllegalArgumentException("Invalid character found.");
}
p = token.backP + encLength;
}
break;
} // switch (c)
Expand Down

0 comments on commit 4fdf926

Please sign in to comment.