Skip to content

refactor(yaml): add skipComment() method #6588

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

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions yaml/_loader_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ export class LoaderState {
this.readIndent();
}

skipComment() {
let ch = this.peek();
if (ch !== SHARP) return;
ch = this.next();
while (ch !== 0 && !isEOL(ch)) {
ch = this.next();
}
}

readIndent() {
let char = this.peek();
while (char === SPACE) {
Expand Down Expand Up @@ -534,10 +543,9 @@ export class LoaderState {
ch = this.next();
}

if (allowComments && ch === SHARP) {
do {
ch = this.next();
} while (ch !== LINE_FEED && ch !== CARRIAGE_RETURN && ch !== 0);
if (allowComments) {
this.skipComment();
ch = this.peek();
}

if (isEOL(ch)) {
Expand Down Expand Up @@ -996,11 +1004,8 @@ export class LoaderState {
ch = this.next();
} while (isWhiteSpace(ch));

if (ch === SHARP) {
do {
ch = this.next();
} while (!isEOL(ch) && ch !== 0);
}
this.skipComment();
ch = this.peek();
}

while (ch !== 0) {
Expand Down Expand Up @@ -1640,12 +1645,8 @@ export class LoaderState {
ch = this.next();
}

if (ch === SHARP) {
do {
ch = this.next();
} while (ch !== 0 && !isEOL(ch));
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now miss this break path. Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. A yaml comment ends only on eol or eof. The yaml string will be invalid on eof at that stage and eol is handled by the next line if (isEOL(ch)) break;.

}
this.skipComment();
ch = this.peek();

if (isEOL(ch)) break;

Expand Down
Loading