Skip to content

Instantly share code, notes, and snippets.

@enebo
Created April 21, 2015 17:42
Show Gist options
  • Save enebo/c77cf0305e64b28eb5c0 to your computer and use it in GitHub Desktop.
Save enebo/c77cf0305e64b28eb5c0 to your computer and use it in GitHub Desktop.
diff --git a/core/src/main/java/org/jruby/Ruby.java b/core/src/main/java/org/jruby/Ruby.java
index b71f65c..bf0f161 100644
--- a/core/src/main/java/org/jruby/Ruby.java
+++ b/core/src/main/java/org/jruby/Ruby.java
@@ -39,6 +39,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;
+import org.jcodings.specific.UTF8Encoding;
import org.jruby.ast.ArrayNode;
import org.jruby.ast.BlockNode;
import org.jruby.ast.CallNode;
@@ -2750,7 +2751,7 @@ public final class Ruby implements Constantizable {
}
parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding()));
} else {
- parserConfig.setDefaultEncoding(getEncodingService().getLocaleEncoding());
+ parserConfig.setDefaultEncoding(UTF8Encoding.INSTANCE);
}
}
diff --git a/core/src/main/java/org/jruby/lexer/GetsLexerSource.java b/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
index 7bff477..792f8fd 100644
--- a/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
+++ b/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
@@ -18,17 +18,25 @@ public class GetsLexerSource extends LexerSource {
private IRubyObject io;
private Encoding encoding;
private int offset;
-
- public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
- // FIXME: Does this source needs SCRIPT_LINES support?
+
+ // Main-line Parsing constructor
+ public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines, Encoding encoding) {
super(sourceName, line, scriptLines);
-
+
this.io = io;
- encoding = frobnicateEncoding();
+ this.encoding = encoding;
+ }
+
+ // FIXME: ripper probably has same problem as main-line parser so this constructor may need to be a mix
+ // of frobbing the encoding of an incoming object plus defaultEncoding if not. but main-line parser
+ // should not be asking IO for encoding.
+ // Ripper constructor
+ public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
+ this(sourceName, line, io, scriptLines, frobnicateEncoding(io));
}
// FIXME: Should be a hard failure likely if no encoding is possible
- public final Encoding frobnicateEncoding() {
+ public static final Encoding frobnicateEncoding(IRubyObject io) {
// Non-ripper IO will not have encoding so we will just use default external
if (!io.respondsTo("encoding")) return io.getRuntime().getDefaultExternalEncoding();
diff --git a/core/src/main/java/org/jruby/parser/Parser.java b/core/src/main/java/org/jruby/parser/Parser.java
index be3aab4..94fe87c 100644
--- a/core/src/main/java/org/jruby/parser/Parser.java
+++ b/core/src/main/java/org/jruby/parser/Parser.java
@@ -83,7 +83,7 @@ public class Parser {
public Node parse(String file, byte[] content, DynamicScope blockScope,
ParserConfiguration configuration) {
RubyArray list = getLines(configuration, runtime, file);
- ByteList in = new ByteList(content, runtime.getDefaultExternalEncoding());
+ ByteList in = new ByteList(content, configuration.getDefaultEncoding());
LexerSource lexerSource = new ByteListLexerSource(file, configuration.getLineNumber(), in, list);
return parse(file, lexerSource, blockScope, configuration);
}
@@ -96,7 +96,7 @@ public class Parser {
} else {
RubyArray list = getLines(configuration, runtime, file);
RubyIO io = RubyIO.newIO(runtime, Channels.newChannel(content));
- LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list);
+ LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list, configuration.getDefaultEncoding());
return parse(file, lexerSource, blockScope, configuration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment