Skip to content

Commit 016793f

Browse files
committed
fix(lint): the missing-audio check skips audio tags that scripts build as strings
1 parent 15482a2 commit 016793f

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎packages/lint/src/hevcPreviewLint.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ describe("collectLocalVideoCandidates", () => {
4040
expect([...candidates.keys()]).toEqual([join(dir, "design/styleframes/clip.mp4")]);
4141
});
4242

43+
it("finds a double-quoted src whose name contains an apostrophe", () => {
44+
const dir = makeProject(["assets/Ann's clip.mp4"]);
45+
46+
const candidates = collectLocalVideoCandidates(dir, [
47+
{ html: `<video src="assets/Ann's clip.mp4"></video>` },
48+
]);
49+
50+
expect([...candidates.keys()]).toEqual([join(dir, "assets/Ann's clip.mp4")]);
51+
});
52+
4353
it("still resolves project-root refs that have no sibling", () => {
4454
const dir = makeProject(["assets/clip.mp4"]);
4555

‎packages/lint/src/project.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,14 @@ describe("a double-quoted src that contains an apostrophe", () => {
833833
expect(codes).toContain("audio_src_not_found");
834834
});
835835

836+
it("does not read an audio tag that an inline script builds as a string", async () => {
837+
const codes = await lintCodes(
838+
`<script>var s = '<audio src="' + u + '">'; var t = "<audio src='" + u + "'>";</script>`,
839+
[],
840+
);
841+
expect(codes).not.toContain("audio_src_not_found");
842+
});
843+
836844
it("does not read a src out of another attribute's text", async () => {
837845
const codes = await lintCodes(`<img id="i1" alt="x src='ghost.png'" />`, []);
838846
expect(codes).not.toContain("missing_local_asset");

‎packages/lint/src/project.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,9 @@ function lintAudioSrcNotFound(
370370

371371
const missingByFile = new Map<string, Set<string>>();
372372
for (const { html, compSrcPath } of htmlSources) {
373+
const scannable = maskNonScannableRanges(html);
373374
let match: RegExpExecArray | null;
374-
while ((match = audioSrcRe.exec(html)) !== null) {
375+
while ((match = audioSrcRe.exec(scannable)) !== null) {
375376
const src = mediaSrcOf(match);
376377
if (/^(https?:|data:|blob:)/i.test(src)) continue;
377378
if (isUnresolvedAssetPlaceholder(src)) continue;

0 commit comments

Comments
 (0)