mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
fix(source-maps): reject empty comma-delimited mappings (#11970)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
ac838a7f48
commit
224856bf62
2 files changed
+31
-3
No files matched your search
@@ -268,9 +268,15 @@ const inspectMappingLayout = (
|
||||
let segments = 0;
|
||||
let components = 0;
|
||||
let inSegment = false;
|
||||
let afterComma = false;
|
||||
let continued = false;
|
||||
let digits = 0;
|
||||
const finish = (): void => {
|
||||
const finish = (requiresSegment: boolean): void => {
|
||||
if (requiresSegment && !inSegment)
|
||||
throw malformedInput(
|
||||
SOURCE_MAP_FORMAT,
|
||||
"Source-map mappings contain an empty mapping segment.",
|
||||
);
|
||||
if (continued)
|
||||
throw malformedInput(
|
||||
SOURCE_MAP_FORMAT,
|
||||
@@ -286,7 +292,9 @@ const inspectMappingLayout = (
|
||||
for (const character of mappings) {
|
||||
if ((index++ & 0x3fff) === 0) check?.();
|
||||
if (character === "," || character === ";") {
|
||||
finish();
|
||||
const isComma = character === ",";
|
||||
finish(isComma || afterComma);
|
||||
afterComma = isComma;
|
||||
inSegment = false;
|
||||
components = 0;
|
||||
if (character === ";") lines += 1;
|
||||
@@ -317,7 +325,7 @@ const inspectMappingLayout = (
|
||||
: limits.decodedRows,
|
||||
);
|
||||
}
|
||||
finish();
|
||||
finish(afterComma);
|
||||
return { lines, segments };
|
||||
};
|
||||
|
||||
|
||||
@@ -330,6 +330,26 @@ describe("source-map layout admission", () => {
|
||||
expect(() => trace({ ...leaf, mappings })).toThrow();
|
||||
},
|
||||
);
|
||||
it.each([",", ",AAAA", "AAAA,,A", "AAAA,", "AAAA,;A"])(
|
||||
"rejects empty mapping segments around commas: %s",
|
||||
(mappings) => {
|
||||
expect(() => trace({ ...leaf, mappings })).toThrow(
|
||||
/empty mapping segment/u,
|
||||
);
|
||||
},
|
||||
);
|
||||
it("retains empty generated lines and generated-only mappings", () => {
|
||||
const report = traceSourceMap(
|
||||
JSON.stringify({ ...leaf, mappings: ";;A,CAAA;" }),
|
||||
url,
|
||||
{ line: 3, column: 0 },
|
||||
);
|
||||
expect(report.lookup.matched_generated_position).toEqual({
|
||||
line: 3,
|
||||
column: 0,
|
||||
});
|
||||
expect(report.matches).toEqual([{ state: "generated-only" }]);
|
||||
});
|
||||
it("validates regular-map source indexes after reusing its decoded rows", () => {
|
||||
expect(() => trace({ ...leaf, mappings: "ACAA" })).toThrow(/index/u);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user