Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
940345dace Fix YAML parser to not treat document markers as special inside quoted strings
Per Dylan's guidance on issue #22392, removed the document marker checks
(--- and ...) from scanSingleQuotedScalar and scanDoubleQuotedScalar.

Document markers should only be recognized at the start of a line in the
main document flow, not within quoted strings where they should be treated
as literal text.

Also removed the now-unused UnexpectedDocumentStart and UnexpectedDocumentEnd
error types from both scanner functions.

Note: There's a separate pre-existing issue where multiline quoted strings
don't parse correctly in Bun's YAML implementation, but that's beyond the
scope of this fix.

Fixes #22392
2025-09-04 07:09:33 +00:00

View File

@@ -2836,8 +2836,6 @@ pub fn Parser(comptime enc: Encoding) type {
const ScanSingleQuotedScalarError = OOM || error{
UnexpectedCharacter,
UnexpectedDocumentStart,
UnexpectedDocumentEnd,
};
fn scanSingleQuotedScalar(self: *@This()) ScanSingleQuotedScalarError!Token(enc) {
@@ -2847,26 +2845,16 @@ pub fn Parser(comptime enc: Encoding) type {
var text: std.ArrayList(enc.unit()) = .init(self.allocator);
var nl = false;
next: switch (self.next()) {
0 => return error.UnexpectedCharacter,
'.' => {
if (nl and self.remainStartsWith("...") and self.isSWhiteOrBCharAt(3)) {
return error.UnexpectedDocumentEnd;
}
nl = false;
try text.append('.');
self.inc(1);
continue :next self.next();
},
'-' => {
if (nl and self.remainStartsWith("---") and self.isSWhiteOrBCharAt(3)) {
return error.UnexpectedDocumentStart;
}
nl = false;
try text.append('-');
self.inc(1);
continue :next self.next();
@@ -2875,7 +2863,6 @@ pub fn Parser(comptime enc: Encoding) type {
'\r',
'\n',
=> {
nl = true;
self.newline();
self.inc(1);
switch (self.foldLines()) {
@@ -2893,7 +2880,6 @@ pub fn Parser(comptime enc: Encoding) type {
' ',
'\t',
=> {
nl = false;
const off = self.pos;
self.inc(1);
self.skipSWhite();
@@ -2904,7 +2890,6 @@ pub fn Parser(comptime enc: Encoding) type {
},
'\'' => {
nl = false;
self.inc(1);
if (self.next() == '\'') {
try text.append('\'');
@@ -2928,7 +2913,6 @@ pub fn Parser(comptime enc: Encoding) type {
});
},
else => |c| {
nl = false;
try text.append(c);
self.inc(1);
continue :next self.next();
@@ -2938,8 +2922,6 @@ pub fn Parser(comptime enc: Encoding) type {
const ScanDoubleQuotedScalarError = OOM || error{
UnexpectedCharacter,
UnexpectedDocumentStart,
UnexpectedDocumentEnd,
};
fn scanDoubleQuotedScalar(self: *@This()) ScanDoubleQuotedScalarError!Token(enc) {
@@ -2948,26 +2930,16 @@ pub fn Parser(comptime enc: Encoding) type {
const scalar_indent = self.line_indent;
var text: std.ArrayList(enc.unit()) = .init(self.allocator);
var nl = false;
next: switch (self.next()) {
0 => return error.UnexpectedCharacter,
'.' => {
if (nl and self.remainStartsWith("...") and self.isSWhiteOrBCharAt(3)) {
return error.UnexpectedDocumentEnd;
}
nl = false;
try text.append('.');
self.inc(1);
continue :next self.next();
},
'-' => {
if (nl and self.remainStartsWith("---") and self.isSWhiteOrBCharAt(3)) {
return error.UnexpectedDocumentStart;
}
nl = false;
try text.append('-');
self.inc(1);
continue :next self.next();
@@ -2988,14 +2960,12 @@ pub fn Parser(comptime enc: Encoding) type {
return error.UnexpectedCharacter;
}
}
nl = true;
continue :next self.next();
},
' ',
'\t',
=> {
nl = false;
const off = self.pos;
self.inc(1);
self.skipSWhite();
@@ -3006,7 +2976,6 @@ pub fn Parser(comptime enc: Encoding) type {
},
'"' => {
nl = false;
self.inc(1);
return .scalar(.{
.start = start,
@@ -3023,7 +2992,6 @@ pub fn Parser(comptime enc: Encoding) type {
},
'\\' => {
nl = false;
self.inc(1);
switch (self.next()) {
'\r',
@@ -3094,7 +3062,6 @@ pub fn Parser(comptime enc: Encoding) type {
},
else => |c| {
nl = false;
try text.append(c);
self.inc(1);
continue :next self.next();