From d7a6ded7aa73611b3b9c2ec02b408f5c1651754c Mon Sep 17 00:00:00 2001 From: Artem Chikin Date: Mon, 19 Oct 2020 16:54:14 -0700 Subject: [PATCH] [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. --- lib/FrontendTool/ScanDependencies.cpp | 5 +---- .../Inputs/unicode_fil\321\221nam\321\221.swift" | 3 +++ test/ScanDependencies/unicode_filename.swift | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 "test/ScanDependencies/Inputs/unicode_fil\321\221nam\321\221.swift" create mode 100644 test/ScanDependencies/unicode_filename.swift diff --git a/lib/FrontendTool/ScanDependencies.cpp b/lib/FrontendTool/ScanDependencies.cpp index f8267d9fd2b13..f40d9c44a6892 100644 --- a/lib/FrontendTool/ScanDependencies.cpp +++ b/lib/FrontendTool/ScanDependencies.cpp @@ -307,7 +307,7 @@ namespace { StringRef value, unsigned indentLevel) { out << "\""; - out.write_escaped(value); + out << value; out << "\""; } @@ -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, @@ -613,7 +611,6 @@ static void writeJSON(llvm::raw_ostream &out, out << ","; out << "\n"; } - } } static bool diagnoseCycle(CompilerInstance &instance, diff --git "a/test/ScanDependencies/Inputs/unicode_fil\321\221nam\321\221.swift" "b/test/ScanDependencies/Inputs/unicode_fil\321\221nam\321\221.swift" new file mode 100644 index 0000000000000..a77e5bfc5cec8 --- /dev/null +++ "b/test/ScanDependencies/Inputs/unicode_fil\321\221nam\321\221.swift" @@ -0,0 +1,3 @@ +func foo() { + print(1) +} diff --git a/test/ScanDependencies/unicode_filename.swift b/test/ScanDependencies/unicode_filename.swift new file mode 100644 index 0000000000000..d86fd78ac1b7c --- /dev/null +++ b/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: ],