Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/review/content-lane/duplicates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ function isBlockScalarHeader(raw: string): boolean {
}

function unquoteYamlScalar(value: string): string {
const trimmed = value.trim();
const trimmed = stripYamlComment(value);
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
return trimmed.slice(1, -1).trim();
}
return trimmed.replace(/\s+#.*$/, "").trim();
return trimmed.trim();
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/review/content-lane/source-evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function unquoteYamlValue(value: string): string {
}

function unquoteYamlScalar(value: string): string {
const trimmed = value.trim();
const trimmed = stripYamlComment(value);
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
return trimmed.slice(1, -1).trim();
}
return trimmed.replace(/\s+#.*$/, "").trim();
return trimmed.trim();
}

// A YAML block-scalar header indicator: `|` or `>` with an optional chomping (`+`/`-`) and/or a single indentation
Expand Down Expand Up @@ -186,6 +186,10 @@ function parseSimpleFrontmatter(source: string): Record<string, string> {
return fields;
}

export const __sourceEvidenceInternals = {
parseSimpleFrontmatter,
};

function frontmatterBlock(source: string): string {
const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(String(source || ""));
return match?.[1] || "";
Expand Down
26 changes: 26 additions & 0 deletions test/unit/content-lane-frontmatter-inline-comment.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { describe, expect, it } from "vitest";
import { parseSimpleFrontmatter as parseDuplicateFrontmatter } from "../../src/review/content-lane/duplicates";
import { __sourceEvidenceInternals } from "../../src/review/content-lane/source-evidence";

const quotedWithComment = '---\ntitle: "My Skill" # published 2024\n---\n';

describe("content-lane frontmatter scalar comments", () => {
it("removes an inline comment before unquoting in the duplicate parser", () => {
expect(parseDuplicateFrontmatter(quotedWithComment).title).toBe("My Skill");
});

it("removes an inline comment before unquoting in the source-evidence parser", () => {
expect(__sourceEvidenceInternals.parseSimpleFrontmatter(quotedWithComment).title).toBe("My Skill");
});

it("preserves existing scalar behavior in both parsers", () => {
const parsers = [parseDuplicateFrontmatter, __sourceEvidenceInternals.parseSimpleFrontmatter];

for (const parse of parsers) {
expect(parse('---\ntitle: plain # note\n---\n').title).toBe("plain");
expect(parse('---\ntitle: "quoted"\n---\n').title).toBe("quoted");
expect(parse("---\ntitle: unadorned\n---\n").title).toBe("unadorned");
expect(parse("---\ntitle: 'single quoted' # note\n---\n").title).toBe("single quoted");
}
});
});
Loading