Advertisement
Guest User

Untitled

a guest
May 30th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.90 KB | None | 0 0
  1. diff --git a/core/src/main/java/org/jruby/Ruby.java b/core/src/main/java/org/jruby/Ruby.java
  2. index b71f65c..bf0f161 100644
  3. --- a/core/src/main/java/org/jruby/Ruby.java
  4. +++ b/core/src/main/java/org/jruby/Ruby.java
  5. @@ -39,6 +39,7 @@
  6. ***** END LICENSE BLOCK *****/
  7. package org.jruby;
  8.  
  9. +import org.jcodings.specific.UTF8Encoding;
  10. import org.jruby.ast.ArrayNode;
  11. import org.jruby.ast.BlockNode;
  12. import org.jruby.ast.CallNode;
  13. @@ -2750,7 +2751,7 @@ public final class Ruby implements Constantizable {
  14. }
  15. parserConfig.setDefaultEncoding(getEncodingService().getEncodingFromString(config.getSourceEncoding()));
  16. } else {
  17. - parserConfig.setDefaultEncoding(getEncodingService().getLocaleEncoding());
  18. + parserConfig.setDefaultEncoding(UTF8Encoding.INSTANCE);
  19. }
  20. }
  21.  
  22. diff --git a/core/src/main/java/org/jruby/lexer/GetsLexerSource.java b/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
  23. index 7bff477..792f8fd 100644
  24. --- a/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
  25. +++ b/core/src/main/java/org/jruby/lexer/GetsLexerSource.java
  26. @@ -18,17 +18,25 @@ public class GetsLexerSource extends LexerSource {
  27. private IRubyObject io;
  28. private Encoding encoding;
  29. private int offset;
  30. -
  31. - public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
  32. - // FIXME: Does this source needs SCRIPT_LINES support?
  33. +
  34. + // Main-line Parsing constructor
  35. + public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines, Encoding encoding) {
  36. super(sourceName, line, scriptLines);
  37. -
  38. +
  39. this.io = io;
  40. - encoding = frobnicateEncoding();
  41. + this.encoding = encoding;
  42. + }
  43. +
  44. + // FIXME: ripper probably has same problem as main-line parser so this constructor may need to be a mix
  45. + // of frobbing the encoding of an incoming object plus defaultEncoding if not. but main-line parser
  46. + // should not be asking IO for encoding.
  47. + // Ripper constructor
  48. + public GetsLexerSource(String sourceName, int line, IRubyObject io, RubyArray scriptLines) {
  49. + this(sourceName, line, io, scriptLines, frobnicateEncoding(io));
  50. }
  51.  
  52. // FIXME: Should be a hard failure likely if no encoding is possible
  53. - public final Encoding frobnicateEncoding() {
  54. + public static final Encoding frobnicateEncoding(IRubyObject io) {
  55. // Non-ripper IO will not have encoding so we will just use default external
  56. if (!io.respondsTo("encoding")) return io.getRuntime().getDefaultExternalEncoding();
  57.  
  58. diff --git a/core/src/main/java/org/jruby/parser/Parser.java b/core/src/main/java/org/jruby/parser/Parser.java
  59. index be3aab4..94fe87c 100644
  60. --- a/core/src/main/java/org/jruby/parser/Parser.java
  61. +++ b/core/src/main/java/org/jruby/parser/Parser.java
  62. @@ -83,7 +83,7 @@ public class Parser {
  63. public Node parse(String file, byte[] content, DynamicScope blockScope,
  64. ParserConfiguration configuration) {
  65. RubyArray list = getLines(configuration, runtime, file);
  66. - ByteList in = new ByteList(content, runtime.getDefaultExternalEncoding());
  67. + ByteList in = new ByteList(content, configuration.getDefaultEncoding());
  68. LexerSource lexerSource = new ByteListLexerSource(file, configuration.getLineNumber(), in, list);
  69. return parse(file, lexerSource, blockScope, configuration);
  70. }
  71. @@ -96,7 +96,7 @@ public class Parser {
  72. } else {
  73. RubyArray list = getLines(configuration, runtime, file);
  74. RubyIO io = RubyIO.newIO(runtime, Channels.newChannel(content));
  75. - LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list);
  76. + LexerSource lexerSource = new GetsLexerSource(file, configuration.getLineNumber(), io, list, configuration.getDefaultEncoding());
  77. return parse(file, lexerSource, blockScope, configuration);
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement