KonghaYao / i18nation

2 stars 1 forks source link

Fix/html replacer换行和无属性时报错 #2

Closed fish0710 closed 2 months ago

fish0710 commented 2 months ago

Summary by Sourcery

Fix errors in the HTML replacer when elements have no attributes and enhance the replacer to ignore carriage return characters in attribute keys.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 2 months ago

Reviewer's Guide by Sourcery

This pull request addresses two issues in the HTML replacer functionality: handling of elements without attributes and filtering out carriage return characters in attribute names. The changes are implemented in the createHTMLReplacer function within the src/replacer/html.ts file.

File-Level Changes

Files Changes
src/replacer/html.ts Added a null check using the optional chaining operator (?.) before calling forEach on astNode.content.attributes to prevent errors when an element has no attributes.
src/replacer/html.ts Implemented a filter to skip processing of attributes with a key content of '\r' (carriage return) to avoid issues with newline characters in attribute names.

Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.