Skip to content

Commit d7a6ded

Browse files
committed
[Dependency Scanner] Do not escape strings in the scanner output
When outputting strings for things like filenames, using `write_escaped` will result in Unicode characters being outputted with a full 3-character-octal or hex escape. Clients which expect a UTF-8 JSON output will not be able to parse such escape sequences.
1 parent 38c8bbd commit d7a6ded

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace {
307307
StringRef value,
308308
unsigned indentLevel) {
309309
out << "\"";
310-
out.write_escaped(value);
310+
out << value;
311311
out << "\"";
312312
}
313313

@@ -460,8 +460,6 @@ static void writeJSON(llvm::raw_ostream &out,
460460
writeJSONSingleField(out, "modulePath", modulePath, /*indentLevel=*/3,
461461
/*trailingComma=*/true);
462462

463-
// Artem Refactoring
464-
{
465463
// Source files.
466464
if (swiftTextualDeps) {
467465
writeJSONSingleField(out, "sourceFiles", swiftTextualDeps->sourceFiles, 3,
@@ -613,7 +611,6 @@ static void writeJSON(llvm::raw_ostream &out,
613611
out << ",";
614612
out << "\n";
615613
}
616-
}
617614
}
618615

619616
static bool diagnoseCycle(CompilerInstance &instance,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func foo() {
2+
print(1)
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -scan-dependencies %s %S/Inputs/unicode_filёnamё.swift -o %t/deps.json
3+
4+
// Check the contents of the JSON output
5+
// RUN: %FileCheck %s < %t/deps.json
6+
7+
print(foo())
8+
9+
// CHECK: "swift": "deps"
10+
// CHECK-NEXT: },
11+
// CHECK-NEXT: {
12+
// CHECK-NEXT: "modulePath": "deps.swiftmodule",
13+
// CHECK-NEXT: "sourceFiles": [
14+
// CHECK-NEXT: "{{.*}}ScanDependencies{{/|\\}}unicode_filename.swift",
15+
// CHECK-NEXT: "{{.*}}ScanDependencies{{/|\\}}Inputs{{/|\\}}unicode_filёnamё.swift"
16+
// CHECK-NEXT: ],

0 commit comments

Comments
 (0)