Skip to content

Commit 9a145fc

Browse files
committed
Adopt XStringNode encoding flags
1 parent 7c2888b commit 9a145fc

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
subject: "String"
2+
description: "backtick literal / encoding / when there are non-ASCII characters"
3+
notes: >
4+
String may be forced to the BINARY (ASCII-8BIT) encoding sometimes
5+
focused_on_node: "org.truffleruby.language.dispatch.RubyCallNode"
6+
ruby: |
7+
# encoding: us-ascii
8+
`echo \xFF 1`
9+
ast: |
10+
RubyCallNode
11+
attributes:
12+
descriptor = NoKeywordArgumentsDescriptor
13+
dispatchConfig = PRIVATE
14+
emptyKeywordsProfile = false
15+
flags = 1
16+
isAttrAssign = false
17+
isSafeNavigation = false
18+
isSplatted = false
19+
isVCall = false
20+
lastArgIsNotHashProfile = false
21+
methodName = "`"
22+
notEmptyKeywordsProfile = false
23+
notRuby2KeywordsHashProfile = false
24+
children:
25+
arguments = [
26+
StringLiteralNode
27+
attributes:
28+
encoding = ASCII-8BIT
29+
flags = 0
30+
tstring = echo \xFF 1
31+
]
32+
receiver =
33+
SelfNode
34+
attributes:
35+
flags = 0
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
subject: "String"
2+
description: "backtick literal / 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.dispatch.RubyCallNode"
6+
ruby: |
7+
# encoding: us-ascii
8+
`echo \u{A3} 1`
9+
ast: |
10+
RubyCallNode
11+
attributes:
12+
descriptor = NoKeywordArgumentsDescriptor
13+
dispatchConfig = PRIVATE
14+
emptyKeywordsProfile = false
15+
flags = 1
16+
isAttrAssign = false
17+
isSafeNavigation = false
18+
isSplatted = false
19+
isVCall = false
20+
lastArgIsNotHashProfile = false
21+
methodName = "`"
22+
notEmptyKeywordsProfile = false
23+
notRuby2KeywordsHashProfile = false
24+
children:
25+
arguments = [
26+
StringLiteralNode
27+
attributes:
28+
encoding = UTF-8
29+
flags = 0
30+
tstring = echo £ 1
31+
]
32+
receiver =
33+
SelfNode
34+
attributes:
35+
flags = 0

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,18 @@ public RubyNode visitWhileNode(Nodes.WhileNode node) {
28332833
@Override
28342834
public RubyNode visitXStringNode(Nodes.XStringNode node) {
28352835
// TODO: pass flags, needs https://github.com/ruby/yarp/issues/1567
2836-
var stringNode = new Nodes.StringNode(NO_FLAGS, node.unescaped, node.startOffset, node.length);
2836+
// convert EncodingFlags to StringFlags
2837+
int flags = 0;
2838+
2839+
if (node.isForcedBinaryEncoding()) {
2840+
flags |= Nodes.StringFlags.FORCED_BINARY_ENCODING;
2841+
}
2842+
2843+
if (node.isForcedUtf8Encoding()) {
2844+
flags |= Nodes.StringFlags.FORCED_UTF8_ENCODING;
2845+
}
2846+
2847+
var stringNode = new Nodes.StringNode((short) flags, node.unescaped, node.startOffset, node.length);
28372848
final RubyNode string = stringNode.accept(this);
28382849

28392850
final RubyNode rubyNode = createCallNode(new SelfNode(), "`", string);

0 commit comments

Comments
 (0)