From e5e20ab42c7baeb196390bb730cbb9cb7102815c Mon Sep 17 00:00:00 2001 From: erik-krogh Date: Tue, 28 Mar 2023 10:57:13 +0200 Subject: [PATCH 1/3] add backticks around the concrete parse error --- .../extractor/src/com/semmle/js/extractor/AutoBuild.java | 4 ++-- .../diagnostics/syntax-error/diagnostics.expected | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index 3b86ed15f8e5..a2da051451a1 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -1236,8 +1236,8 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state) if (!extractor.getConfig().isExterns()) seenFiles = true; List errors = loc == null ? Collections.emptyList() : loc.getParseErrors(); for (ParseError err : errors) { - String msg = "A parse error occurred: " + StringUtil.escapeMarkdown(err.getMessage()) - + ". Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; + String msg = "A parse error occurred: `" + StringUtil.escapeMarkdown(err.getMessage()).trim() + + "`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; // file, relative to the source root String relativeFilePath = null; if (file.startsWith(LGTM_SRC)) { diff --git a/javascript/ql/integration-tests/all-platforms/diagnostics/syntax-error/diagnostics.expected b/javascript/ql/integration-tests/all-platforms/diagnostics/syntax-error/diagnostics.expected index 0c4405ea92b0..c1ee74852189 100644 --- a/javascript/ql/integration-tests/all-platforms/diagnostics/syntax-error/diagnostics.expected +++ b/javascript/ql/integration-tests/all-platforms/diagnostics/syntax-error/diagnostics.expected @@ -6,7 +6,7 @@ "startColumn": 4, "startLine": 1 }, - "markdownMessage": "A parse error occurred: Unexpected token. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.", + "markdownMessage": "A parse error occurred: `Unexpected token`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis.", "severity": "warning", "source": { "extractorName": "javascript", From 70dfa6e15cc9092c2350b097b45ba0a4684b618a Mon Sep 17 00:00:00 2001 From: erik-krogh Date: Tue, 28 Mar 2023 12:34:44 +0200 Subject: [PATCH 2/3] use StringUtil.quoteWithBackticks instead of manually quoting with a single backtick --- .../extractor/src/com/semmle/js/extractor/AutoBuild.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index a2da051451a1..2874d5105126 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -1236,8 +1236,8 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state) if (!extractor.getConfig().isExterns()) seenFiles = true; List errors = loc == null ? Collections.emptyList() : loc.getParseErrors(); for (ParseError err : errors) { - String msg = "A parse error occurred: `" + StringUtil.escapeMarkdown(err.getMessage()).trim() - + "`. Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; + String msg = "A parse error occurred: " + StringUtil.quoteWithBackticks(StringUtil.escapeMarkdown(err.getMessage()).trim()) + + ". Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; // file, relative to the source root String relativeFilePath = null; if (file.startsWith(LGTM_SRC)) { From 4b3a4195094b950f587f53993fc95e3417642649 Mon Sep 17 00:00:00 2001 From: erik-krogh Date: Tue, 28 Mar 2023 15:23:15 +0200 Subject: [PATCH 3/3] just use quoteWithBackticks --- javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java index 2874d5105126..346d31231df9 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java +++ b/javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java @@ -1236,7 +1236,7 @@ private void doExtract(FileExtractor extractor, Path file, ExtractorState state) if (!extractor.getConfig().isExterns()) seenFiles = true; List errors = loc == null ? Collections.emptyList() : loc.getParseErrors(); for (ParseError err : errors) { - String msg = "A parse error occurred: " + StringUtil.quoteWithBackticks(StringUtil.escapeMarkdown(err.getMessage()).trim()) + String msg = "A parse error occurred: " + StringUtil.quoteWithBackticks(err.getMessage().trim()) + ". Check the syntax of the file. If the file is invalid, correct the error or [exclude](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/customizing-code-scanning) the file from analysis."; // file, relative to the source root String relativeFilePath = null;