Skip to content

fix(baoyu-post-to-wechat): read HTML image paths with quotes and entities - #241

Open
chuenchen309 wants to merge 1 commit into
JimLiu:mainfrom
chuenchen309:fix/wechat-html-image-attrs
Open

chuenchen309 wants to merge 1 commit into
JimLiu:mainfrom
chuenchen309:fix/wechat-html-image-attrs

Conversation

@chuenchen309

Copy link
Copy Markdown

Summary

When an HTML file is posted (an .html file to the API method, or the browser method's --html), wechat-api.ts and wechat-article.ts read each <img>'s src and data-local-path with ["']([^"']+)["']. That regex stops at an apostrophe inside a double-quoted value and leaves entities encoded. baoyu-markdown-to-html escapes these attributes, so its output for ![a](Q&A.png) and ![b](it's.png) is:

<img src="Q&amp;A.png" data-local-path="/posts/Q&amp;A.png" ...>
<img src="it's.png" data-local-path="/posts/it's.png" ...>

and the API path then fails to load both (Image not found: /posts/Q&amp;A.png, Image not found: /posts/it). The upload error is only logged, so the draft is saved without those images.

  • add getTagAttribute(tag, name) to wechat-image-loader.ts: takes a double- or single-quoted value whole and decodes &amp;, &quot;, &#39;, &apos;, &lt;, &gt;
  • use it for src and data-local-path in uploadImagesInHtml and in the browser method's HTML parsing, and make the src / data-local-path rewrites in uploadImagesInHtml use the same quoting

Tests

  • new wechat-image-loader.test.ts (entities, the other quote inside a value, data-src not read as src)
  • ran baoyu-markdown-to-html on a post with Q&A.png, it's.png and plain.png, then passed each <img> through the old and new extraction into loadUploadAsset: before, only plain.png loads; after, all three do
  • npm test (as in CI, after npm ci and the wechat scripts install): 270 passed; cd skills/baoyu-post-to-wechat/scripts && bun test: 42 passed (39 on main)
  • not run against a real WeChat account or the browser method
…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T01:26:24.027246Z de26b5f PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant