Skip to content

Commit 8cd8369

Browse files
committed
Add early check that the source encoding is ASCII compatible
* The check in RubyLexer is too late, at that point the TruffleString is already in a non-ASCII compatible encoding and the check does not work.
1 parent cb26e29 commit 8cd8369

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/org/truffleruby/parser/TranslatorDriver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
114114
"A frame should be given iff the context is not toplevel: " + parserContext + " " + parentFrame);
115115
}
116116

117+
if (!rubySource.getEncoding().isAsciiCompatible) {
118+
throw new RaiseException(context, context.getCoreExceptions()
119+
.argumentError(rubySource.getEncoding() + " is not ASCII compatible", currentNode));
120+
}
121+
117122
final Source source = rubySource.getSource();
118123

119124
final StaticScope staticScope = new StaticScope(StaticScope.Type.LOCAL, null);

src/main/java/org/truffleruby/parser/YARPTranslatorDriver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ public RootCallTarget parse(RubySource rubySource, ParserContext parserContext,
117117
"A frame should be given iff the context is not toplevel: " + parserContext + " " + parentFrame);
118118
}
119119

120+
if (!rubySource.getEncoding().isAsciiCompatible) {
121+
throw new RaiseException(context, context.getCoreExceptions()
122+
.argumentError(rubySource.getEncoding() + " is not ASCII compatible", currentNode));
123+
}
124+
120125
final Source source = rubySource.getSource();
121126

122127
final StaticScope staticScope = new StaticScope(StaticScope.Type.LOCAL, null);

0 commit comments

Comments
 (0)