Skip to content

Commit fc166ca

Browse files
Fixed UTF const.
1 parent 90edeb4 commit fc166ca

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

dd-java-agent/instrumentation/java/java-lang/java-lang-9.0/src/test/groovy/datadog/trace/instrumentation/java/lang/invoke/StringConcatFactoryCallSiteTest.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ class StringConcatFactoryCallSiteTest extends InstrumentationSpecification {
147147
setup:
148148
StringModule iastModule = Mock(StringModule)
149149
InstrumentationBridge.registerIastModule(iastModule)
150-
final expected = '𠆢Hello𠆢\u0001𠆢World!.'
150+
// Explicit escape for non-ASCII symbol to make test independent of container settings.
151+
final utfConstant = '\uD840\uDDA2' // 𠆢
152+
final expected = "${utfConstant}Hello${utfConstant}\u0001${utfConstant}World!."
151153

152154
when:
153155
final result = TestStringConcatFactorySuite.plusWithUtfConstants('Hello', 'World!')
@@ -157,8 +159,8 @@ class StringConcatFactoryCallSiteTest extends InstrumentationSpecification {
157159
1 * iastModule.onStringConcatFactory(
158160
expected,
159161
['Hello', 'World!'] as String[],
160-
'𠆢\u0001\u0002\u0001.',
161-
['𠆢\u0001𠆢'] as Object[],
162+
"${utfConstant}\u0001\u0002\u0001.",
163+
["${utfConstant}\u0001${utfConstant}"] as Object[],
162164
[-2, 0, -5, 1, -1] as int[])
163165
0 * _
164166
}

dd-java-agent/instrumentation/java/java-lang/java-lang-9.0/src/test/java/foo/bar/TestStringConcatFactorySuite.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.slf4j.LoggerFactory;
66

77
public abstract class TestStringConcatFactorySuite {
8+
// Explicit escape for non-ASCII symbol to make test independent of container settings.
9+
private static final String UTF_CONSTANT = "\uD840\uDDA2"; // 𠆢
810

911
private static final Logger LOGGER = LoggerFactory.getLogger(TestStringConcatFactorySuite.class);
1012

@@ -33,7 +35,8 @@ public static String plusWithConstantsAndTags(final String left, final String ri
3335

3436
public static String plusWithUtfConstants(final String left, final String right) {
3537
LOGGER.debug("Before string plus {} {}", left, right);
36-
final String result = "𠆢" + left + "𠆢\u0001𠆢" + right + ".";
38+
final String result =
39+
UTF_CONSTANT + left + UTF_CONSTANT + "\u0001" + UTF_CONSTANT + right + ".";
3740
LOGGER.debug("After string plus {}", result);
3841
return result;
3942
}
@@ -50,7 +53,8 @@ public static String stringPlusWithMultipleObjects(final Object... target) {
5053
LOGGER.debug("Before string plus {}", Arrays.toString(target));
5154
String result = "";
5255
for (final Object item : target) {
53-
result += item;
56+
//noinspection StringConcatenationInLoop
57+
result += item; // intentional `+` in loop for test.
5458
}
5559
LOGGER.debug("After string plus {}", result);
5660
return result;

dd-java-agent/instrumentation/java/java-net/java-net-1.8/src/test/groovy/datadog/trace/instrumentation/java/net/URLEncoderCallSiteTest.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import datadog.trace.api.iast.propagation.PropagationModule
77
import foo.bar.TestURLEncoderCallSiteSuite
88

99
class URLEncoderCallSiteTest extends InstrumentationSpecification {
10+
// Explicit escape for non-ASCII `ståle` to make test independent of container settings.
11+
private static final String NON_ASCII_QUERY = 'my test.asp?name=st\u00E5le&car=saab'
1012

1113
@Override
1214
protected void configurePreAgent() {
@@ -27,9 +29,9 @@ class URLEncoderCallSiteTest extends InstrumentationSpecification {
2729
0 * _
2830

2931
where:
30-
args | expected
31-
['my test.asp?name=ståle&car=saab'] | 'my+test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab'
32-
['my test.asp?name=ståle&car=saab', 'UTF-8'] | 'my+test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab'
32+
args | expected
33+
[NON_ASCII_QUERY] | 'my+test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab'
34+
[NON_ASCII_QUERY, 'UTF-8'] | 'my+test.asp%3Fname%3Dst%C3%A5le%26car%3Dsaab'
3335
}
3436

3537
void 'test encode with null args'() {

0 commit comments

Comments
 (0)