-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix(yaml): do not treat --- or ... inside scalar values as document separators #25686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
majiayu000
wants to merge
2
commits into
oven-sh:main
Choose a base branch
from
majiayu000:claude/fix-yaml-document-separator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /** | ||
| * Regression test for issue #25660 | ||
| * YAML.parse() incorrectly splits on `---` inside values | ||
| * | ||
| * @see https://github.com/oven-sh/bun/issues/25660 | ||
| */ | ||
| import { describe, expect, test } from "bun:test"; | ||
|
|
||
| describe("YAML.parse document separator handling", () => { | ||
| test("should not split on --- inside scalar values", () => { | ||
| const text = ` | ||
| name: some-text--- | ||
| description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. | ||
| `; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ | ||
| name: "some-text---", | ||
| description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", | ||
| }); | ||
| }); | ||
|
|
||
| test("should not split on --- in middle of value", () => { | ||
| const text = `key: hello---world`; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ key: "hello---world" }); | ||
| }); | ||
|
|
||
| test("should not split on ... inside scalar values", () => { | ||
| const text = `key: hello...world`; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ key: "hello...world" }); | ||
| }); | ||
|
|
||
| test("should not treat document markers as values after ':'", () => { | ||
| const text = ` | ||
| key1: --- | ||
| key2: ... | ||
| `; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ key1: "---", key2: "..." }); | ||
| }); | ||
|
|
||
| test("should not treat --- at line start in multiline plain scalar as a document separator", () => { | ||
| const text = ` | ||
| message: first line | ||
| --- still part of the value | ||
| last line | ||
| `; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ | ||
| message: "first line --- still part of the value last line", | ||
| }); | ||
| }); | ||
|
|
||
| test("should correctly handle actual document separator at line start", () => { | ||
| const text = ` | ||
| doc1: value1 | ||
| --- | ||
| doc2: value2 | ||
| `; | ||
| const parsed = Bun.YAML.parse(text); | ||
| // When there's an actual document separator, it returns an array | ||
| expect(Array.isArray(parsed)).toBe(true); | ||
| expect(parsed).toHaveLength(2); | ||
| expect(parsed[0]).toEqual({ doc1: "value1" }); | ||
| expect(parsed[1]).toEqual({ doc2: "value2" }); | ||
| }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test("should handle value ending with multiple dashes", () => { | ||
| const text = ` | ||
| title: My-Title--- | ||
| subtitle: Another---Value--- | ||
| `; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ | ||
| title: "My-Title---", | ||
| subtitle: "Another---Value---", | ||
| }); | ||
| }); | ||
|
|
||
| test("should handle value ending with dots", () => { | ||
| const text = `message: Hello...`; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toEqual({ message: "Hello..." }); | ||
| }); | ||
|
|
||
| test("should recognize ... as document end marker for top-level plain scalar", () => { | ||
| // This is the case Dylan pointed out: a top-level plain scalar followed by | ||
| // document end marker should correctly recognize ... as document end | ||
| const text = `hello | ||
| ...`; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(parsed).toBe("hello"); | ||
| }); | ||
|
|
||
| test("should recognize --- as document separator for top-level plain scalar", () => { | ||
| const text = `first | ||
| --- | ||
| second`; | ||
| const parsed = Bun.YAML.parse(text); | ||
| expect(Array.isArray(parsed)).toBe(true); | ||
| expect(parsed).toHaveLength(2); | ||
| expect(parsed[0]).toBe("first"); | ||
| expect(parsed[1]).toBe("second"); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.