Skip to content

Commit

Permalink
Fixed default encoding for inline scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Apr 22, 2015
1 parent 15584ba commit 9f15d60
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -2732,26 +2732,26 @@ private Node parseFileFromMainAndGetAST(InputStream in, String file, DynamicScop
private Node parseFileAndGetAST(InputStream in, String file, DynamicScope scope, int lineNumber, boolean isFromMain) {
ParserConfiguration parserConfig =
new ParserConfiguration(this, lineNumber, false, true, config);
setupSourceEncoding(parserConfig);
setupSourceEncoding(parserConfig, UTF8Encoding.INSTANCE);
return parser.parse(file, in, scope, parserConfig);
}

public Node parseInline(InputStream in, String file, DynamicScope scope) {
addEvalParseToStats();
ParserConfiguration parserConfig =
new ParserConfiguration(this, 0, false, true, false, config);
setupSourceEncoding(parserConfig);
setupSourceEncoding(parserConfig, getEncodingService().getConsoleEncoding());
return parser.parse(file, in, scope, parserConfig);
}

private void setupSourceEncoding(ParserConfiguration parserConfig) {
private void setupSourceEncoding(ParserConfiguration parserConfig, Encoding defaultEncoding) {
if (config.getSourceEncoding() != null) {
if (config.isVerbose()) {
config.getError().println("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
}
parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding()));
} else {
parserConfig.setDefaultEncoding(UTF8Encoding.INSTANCE);
parserConfig.setDefaultEncoding(defaultEncoding);
}
}

Expand Down

0 comments on commit 9f15d60

Please sign in to comment.