Repository navigation
fix(baoyu-post-to-wechat): read HTML image paths with quotes and entities - #241
chuenchen309 wants to merge 1 commit into
Conversation
…ties The API and browser paths read an <img>'s src and data-local-path with ["']([^"']+)["'], which stops at an apostrophe inside a double-quoted value and leaves entities encoded. baoyu-markdown-to-html escapes the attribute, so an image named Q&A.png or it's.png was not found and its upload was skipped.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de26b5feab
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| * A quote of the other kind belongs to the value: `src="it's.png"` is `it's.png`. | ||
| */ | ||
| export function getTagAttribute(tag: string, name: string): string | undefined { | ||
| const match = tag.match(new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`, "i")); |
There was a problem hiding this comment.
Tokenize attributes before reading their values
When an HTML file has an earlier quoted attribute containing text like src='fake.png' before its real src, this regex can match the text inside that attribute and return fake.png. The API path then uses the wrong source and may skip the actual image or try to load the fake path; parse actual attribute boundaries instead of scanning raw tag text.
Useful? React with 👍 / 👎.
Summary
When an HTML file is posted (an
.htmlfile to the API method, or the browser method's--html),wechat-api.tsandwechat-article.tsread each<img>'ssrcanddata-local-pathwith["']([^"']+)["']. That regex stops at an apostrophe inside a double-quoted value and leaves entities encoded.baoyu-markdown-to-htmlescapes these attributes, so its output forandis:and the API path then fails to load both (
Image not found: /posts/Q&A.png,Image not found: /posts/it). The upload error is only logged, so the draft is saved without those images.getTagAttribute(tag, name)towechat-image-loader.ts: takes a double- or single-quoted value whole and decodes&,",',',<,>srcanddata-local-pathinuploadImagesInHtmland in the browser method's HTML parsing, and make thesrc/data-local-pathrewrites inuploadImagesInHtmluse the same quotingTests
wechat-image-loader.test.ts(entities, the other quote inside a value,data-srcnot read assrc)baoyu-markdown-to-htmlon a post withQ&A.png,it's.pngandplain.png, then passed each<img>through the old and new extraction intoloadUploadAsset: before, onlyplain.pngloads; after, all three donpm test(as in CI, afternpm ciand the wechat scripts install): 270 passed;cd skills/baoyu-post-to-wechat/scripts && bun test: 42 passed (39 on main)