File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed
spec/truffle/parsing/fixtures/strings/encoding
src/main/java/org/truffleruby/parser Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change
1
+ subject : " String"
2
+ description : " encoding / when there are ASCII and non-ASCII characters in a literal"
3
+ notes : >
4
+ String may be forced to the BINARY (ASCII-8BIT) encoding sometimes
5
+ focused_on_node : " org.truffleruby.language.literal.StringLiteralNode"
6
+ ruby : |
7
+ # encoding: us-ascii
8
+ "\xFF"
9
+ ast : |
10
+ StringLiteralNode
11
+ attributes:
12
+ encoding = ASCII-8BIT
13
+ flags = 1
14
+ tstring = \xFF
Original file line number Diff line number Diff line change
1
+ subject : " String"
2
+ description : " encoding / when there are UTF-8 characters in a literal"
3
+ notes : >
4
+ String may be forced to the UTF-8 encoding sometimes
5
+ focused_on_node : " org.truffleruby.language.literal.StringLiteralNode"
6
+ ruby : |
7
+ # encoding: us-ascii
8
+ "\u{A3}"
9
+ ast : |
10
+ StringLiteralNode
11
+ attributes:
12
+ encoding = UTF-8
13
+ flags = 1
14
+ tstring = £
Original file line number Diff line number Diff line change @@ -2711,13 +2711,23 @@ public RubyNode visitStatementsNode(Nodes.StatementsNode node) {
2711
2711
@ Override
2712
2712
public RubyNode visitStringNode (Nodes .StringNode node ) {
2713
2713
final RubyNode rubyNode ;
2714
- final TruffleString tstring = TStringUtils .fromByteArray (node .unescaped , sourceEncoding );
2714
+ final RubyEncoding encoding ;
2715
+
2716
+ if (node .isForcedUtf8Encoding ()) {
2717
+ encoding = Encodings .UTF_8 ;
2718
+ } else if (node .isForcedBinaryEncoding ()) {
2719
+ encoding = Encodings .BINARY ;
2720
+ } else {
2721
+ encoding = sourceEncoding ;
2722
+ }
2723
+
2724
+ final TruffleString tstring = TStringUtils .fromByteArray (node .unescaped , encoding );
2715
2725
2716
2726
if (!node .isFrozen ()) {
2717
- final TruffleString cachedTString = language .tstringCache .getTString (tstring , sourceEncoding );
2718
- rubyNode = new StringLiteralNode (cachedTString , sourceEncoding );
2727
+ final TruffleString cachedTString = language .tstringCache .getTString (tstring , encoding );
2728
+ rubyNode = new StringLiteralNode (cachedTString , encoding );
2719
2729
} else {
2720
- final ImmutableRubyString frozenString = language .getFrozenStringLiteral (tstring , sourceEncoding );
2730
+ final ImmutableRubyString frozenString = language .getFrozenStringLiteral (tstring , encoding );
2721
2731
rubyNode = new FrozenStringLiteralNode (frozenString , FrozenStrings .EXPRESSION );
2722
2732
}
2723
2733
You can’t perform that action at this time.
0 commit comments