RUBY-12161: special case to parse valid octal chars

#RUBY-12161 fixed
This commit is contained in:
Oleg Sukhodolsky
2013-02-09 17:08:11 +04:00
parent 1c5010375c
commit 3426d31844
@@ -57,7 +57,23 @@ public class RegExpCharImpl extends RegExpElementImpl implements RegExpChar {
@Nullable
public Character getValue() {
final String s = getUnescapedText();
if (s.equals("\\") && getType() == Type.CHAR) return '\\';
if (s.equals("\\") && getType() == Type.CHAR) {
return '\\';
}
// special case for valid octal escaped sequences (see RUBY-12161)
if (s.startsWith("\\") && s.length() > 1) {
final ASTNode child = getNode().getFirstChildNode();
assert child != null;
final IElementType t = child.getElementType();
if (t == RegExpTT.OCT_CHAR) {
try {
return (char) Integer.parseInt(s.substring(1), 8);
}
catch (NumberFormatException e) {
// do nothing
}
}
}
return unescapeChar(s);
}