Commit ef12c74b authored by Yang Guo's avatar Yang Guo Committed by Commit Bot

[inspector] fix sourceURL magic comment parsing

R=szuend@chromium.org

Fixed: chromium:1078205
Change-Id: I16f8e19a249692fd16fd53a9a56a8f4cfed8b5c0
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2185134
Auto-Submit: Yang Guo <yangguo@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Reviewed-by: 's avatarSimon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67634}
parent c3566e9e
......@@ -36,7 +36,8 @@ String16 findMagicComment(const String16& content, const String16& name,
if (content[pos + 2] != '#' && content[pos + 2] != '@') continue;
if (content[pos + 3] != ' ' && content[pos + 3] != '\t') continue;
equalSignPos = pos + 4 + nameLength;
if (equalSignPos < length && content[equalSignPos] != '=') continue;
if (equalSignPos >= length) continue;
if (content[equalSignPos] != '=') continue;
if (multiline) {
closingCommentPos = content.find("*/", equalSignPos + 1);
if (closingCommentPos == String16::kNotFound) return String16();
......@@ -46,6 +47,7 @@ String16 findMagicComment(const String16& content, const String16& name,
}
DCHECK(equalSignPos);
DCHECK_LT(equalSignPos, length);
DCHECK(!multiline || closingCommentPos);
size_t urlPos = equalSignPos + 1;
String16 match = multiline
......
Test malformed sourceURL magic comment.
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
{
id : <messageId>
result : {
exceptionDetails : {
columnNumber : 0
exception : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
exceptionId : <exceptionId>
lineNumber : 0
scriptId : <scriptId>
text : Uncaught
}
result : {
className : SyntaxError
description : SyntaxError: Unexpected token / in JSON at position 0 at JSON.parse (<anonymous>) at <anonymous>:1:6
objectId : <objectId>
subtype : error
type : object
}
}
}
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start(
'Test malformed sourceURL magic comment.');
(async function test() {
await Protocol.Debugger.enable();
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//')",
generatePreview: true,
}));
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//#')",
generatePreview: true,
}));
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//# ')",
generatePreview: true,
}));
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//# sourceURL')",
generatePreview: true,
}));
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//# sourceURL=')",
generatePreview: true,
}));
InspectorTest.logMessage(await Protocol.Runtime.evaluate({
expression: "JSON.parse('//# sourceURL=\"')",
generatePreview: true,
}));
InspectorTest.completeTest();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment