Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For Windows.
Browse files Browse the repository at this point in the history
nirvdrum committed Apr 21, 2015
1 parent 214dea5 commit 15584ba
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -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 @@ private void setupSourceEncoding(ParserConfiguration parserConfig) {
}
parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding()));
} else {
parserConfig.setDefaultEncoding(getEncodingService().getLocaleEncoding());
parserConfig.setDefaultEncoding(UTF8Encoding.INSTANCE);
}
}

20 changes: 14 additions & 6 deletions core/src/main/java/org/jruby/lexer/GetsLexerSource.java
Original file line number Diff line number Diff line change
@@ -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();

4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/parser/Parser.java
Original file line number Diff line number Diff line change
@@ -83,7 +83,7 @@ public Node parse(String file, ByteList content, DynamicScope blockScope,
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 Node parse(String file, InputStream content, DynamicScope blockScope,
} 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);
}
}

0 comments on commit 15584ba

Please sign in to comment.