Skip to content

Commit

Permalink
[Dependency Scanner] Do not escape strings in the scanner output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
artemcm committed Oct 20, 2020
1 parent 38c8bbd commit d7a6ded
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/FrontendTool/ScanDependencies.cpp
Expand Up @@ -307,7 +307,7 @@ namespace {
StringRef value,
unsigned indentLevel) {
out << "\"";
out.write_escaped(value);
out << value;
out << "\"";
}

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

// Artem Refactoring
{
// Source files.
if (swiftTextualDeps) {
writeJSONSingleField(out, "sourceFiles", swiftTextualDeps->sourceFiles, 3,
Expand Down Expand Up @@ -613,7 +611,6 @@ static void writeJSON(llvm::raw_ostream &out,
out << ",";
out << "\n";
}
}
}

static bool diagnoseCycle(CompilerInstance &instance,
Expand Down
3 changes: 3 additions & 0 deletions test/ScanDependencies/Inputs/unicode_filёnamё.swift
@@ -0,0 +1,3 @@
func foo() {
print(1)
}
16 changes: 16 additions & 0 deletions test/ScanDependencies/unicode_filename.swift
@@ -0,0 +1,16 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -scan-dependencies %s %S/Inputs/unicode_filёnamё.swift -o %t/deps.json

// Check the contents of the JSON output
// RUN: %FileCheck %s < %t/deps.json

print(foo())

// CHECK: "swift": "deps"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "modulePath": "deps.swiftmodule",
// CHECK-NEXT: "sourceFiles": [
// CHECK-NEXT: "{{.*}}ScanDependencies{{/|\\}}unicode_filename.swift",
// CHECK-NEXT: "{{.*}}ScanDependencies{{/|\\}}Inputs{{/|\\}}unicode_filёnamё.swift"
// CHECK-NEXT: ],

0 comments on commit d7a6ded

Please sign in to comment.