Repository navigation
fix(core): reject references to ids the icon does not define (TSK-111) - #40
Merged
Merged
Conversation
A dangling href="#…", url(#…) in an attribute, style attribute or <style>, or SMIL begin/end reference built with exit 0 and rendered a blank icon. validateTree now reports each one as the error svg/missing-reference, naming the file, the element and the missing id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rejections Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
🤖 hustle review: approve — Dangling href, url(#…) and SMIL begin/end references now fail with svg/missing-reference. Forward references and clock values are handled, tests cover each form, and docs and a patch changeset are present. The only gap is that SMIL ids containing '-' are not checked, which gives a missed error rather than a false rejection. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes RPT-017 / TSK-111. An icon whose
href="#x",url(#x)or SMILbegin/endpoints to an id the file does not define used to build with exit 0 and render blank. It is now an error,svg/missing-reference(principle 5: fail loudly).What changed
packages/svgworm/src/core/errors.ts: newDiagnosticCode.MISSING_REFERENCE = 'svg/missing-reference'.packages/svgworm/src/core/svg/validate.ts:validateTreeaddsfindMissingReferences. It runs on the raw source tree, before svgo andrenameIds. It first collects every id in the document (root included), so forward references such as<use href="#a">before<defs><path id="a">stay valid. Then it checks:href/xlink:href="#id"url(#id)in any attribute, includingstyle(CSS-unescaped), and in<style>textbegin/endid.eventparts. These use the same "letter after the dot" rule asrenameIds, so0.5s,clickandindefiniteare never treated as ids.<use> href="#missing" points to id "missing", which the file does not define.tree.test.ts: the existing "accepts internal references" case usedhref="#a"andurl(#g)with no targets. It now defines those ids.apps/site/src/content/docs/troubleshooting.md(kind: error) and in the error tables of both skills.llms.txtlists no codes (it links to troubleshooting), so it is unchanged.missing-internal-reference.md:svgwormpatch. Earlier validation rejections inCHANGELOG.mdalso shipped as patches.Acceptance criteria
<use href="#missing">andfill="url(#grad)"building with ok: true and no diagnostic. New cases intransform.test.tsand a two-file compile test incompile.test.ts. Before the fix: 6 failed intransform.test.ts, and the compile test failed withexpected true to be false(sookwas true). After the fix they pass. The report's repro through the built CLI: before,{"ok":true,"warnings":[]}. Now:{"ok":false,"errors":[{"code":"svg/missing-reference","file":"icons/danglingfill.svg",…},{"code":"svg/missing-reference","file":"icons/danglingref.svg",…}]}, with exit code 1.vitest run src/core/svg/transform.test.tsgives 20 passed. There is one test each forhref,xlink:href,fill="url()", astyleattribute, a<style>block, andbegin+end. Two more tests check that valid forward references and plain clock values still pass.pnpm verify: exit 0. 951 passed, and no snapshot file changed.pnpm determinism:fingerprint: output is byte-identical tomain(cmpof both runs).pnpm example:check,pnpm example:vite:check,pnpm site:check: exit 0.pnpm render:check: Chromium 57 pass / 0 fail, Firefox 57 pass / 0 fail. WebKit could not launch on this host because system libraries are missing, so the script exited before it rewrotetests/render/matrix.json. The compiled fixture output is byte-identical tomain, so CI's matrix diff should be empty..changeset/missing-internal-reference.md.Backlog: TSK-111 is moved to complete with evidence in its progress log. New learning LRN-071.
🤖 Generated with Claude Code