SVG elements in an HTML document report an upper-cased tagName ("PATH" instead of "path")
メンテナーはふだん 17 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- html, javascript
- 領域
- web-dev
調査の方向性
バグは esm/interface/element.js の118〜119行目にある Element#tagName と Element#nodeName にあり、esm/shared/utils.js の localCase(this) を返しています。まず issue に含まれる再現スクリプトを実行して問題を再現してください。その後、namespaceURI が SVG の名前空間である場合に localName を返す SVG 固有のゲッターを SVGElement に追加します。path と svg が小文字の tagName/nodeName を返し、div などの HTML 要素が引き続き大文字を返し、test/svg/element.js のテストがそれを検証すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
In an HTML document, tagName and nodeName of SVG elements come back upper-cased. Browsers upper-case them only for elements in the HTML namespace. That holds both for elements created with createElementNS and for elements that were parsed.
// npm i [email protected] && node repro.mjs
import { parseHTML } from 'linkedom';
const SVG = 'http://www.w3.org/2000/svg';
const { document } = parseHTML('<!doctype html><html><body><svg><path d="M0 0"/></svg><div></div></body></html>');
console.log(document.createElementNS(SVG, 'path').tagName); // "PATH" (browsers: "path")
console.log(document.createElementNS(SVG, 'path').nodeName); // "PATH" (browsers: "path")
console.log(document.querySelector('path').tagName); // "PATH" (browsers: "path")
console.log(document.querySelector('svg').tagName); // "SVG" (browsers: "svg")
console.log(document.querySelector('div').tagName); // "DIV" (browsers: "DIV", correct)
Same output on 0.18.12, 0.18.13 and main (3fcf145). Node 22.17.0, macOS.
Expected (DOM spec, Element.tagName): the qualified name is upper-cased only "if this is in the HTML namespace and its node document is an HTML document". An SVG element keeps its case: "path", "svg", "foreignObject".
Where it seems to come from: Element#tagName and Element#nodeName both return localCase(this) (esm/interface/element.js#L118-L119). localCase (esm/shared/utils.js#L31-L33) upper-cases whenever the document ignores case and does not look at the namespace. Overriding both getters in SVGElement to return this.localName looks enough. getElementsByTagName already compares localName first, so it would keep working.
Use case: server-side rendering of diagrams. Code written for browsers branches on tagName. For example, mermaid's mergePaths keeps the children whose tagName === 'path', so on linkedom a shape comes out with an empty d. The workaround on our side is a tagName/nodeName getter on the SVG element prototype that returns localName when namespaceURI is SVG.
Happy to send a PR with a test in test/svg/element.js if this is welcome. (Not covered by that change: a parsed <foreignObject> has the localName "foreignobject", which browsers adjust to "foreignObject".)
- 主要言語
- HTML
- スター
- 2.1k
- フォーク
- 112
- 平均マージ
- 11日 1時間
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
WebReflection/linkedom のほかの issue
-
`TextElement.toString()` puts the element text back at the first `><` of the start tag, so an attribute value containing `><` swallows the text of `<style>`, `<script>`, `<title>` and `<textarea>`対応中かも @vsolano9 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
WebReflection/linkedom#341 ·
メンテナーはふだん 17 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
WebReflection/linkedom#340 ·
メンテナーはふだん 17 日以内に返信
-
Element#matches() compiles the selector on every call対応中かも @jonasporto が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
WebReflection/linkedom#348 ·
メンテナーはふだん 17 日以内に返信
-
難易度 3/5 半日 初心者へのやさしさ 50/100
WebReflection/linkedom#345 ·
メンテナーはふだん 17 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
WebReflection/linkedom#342 ·
メンテナーはふだん 17 日以内に返信
WebReflection/linkedom の issue をすべて見る
似ている issue
-
area:plugins enhancement platform:vscode
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
anthropics/claude-code#103166 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
jitsi/jitsi-meet#18021 ·
メンテナーはふだん 1 日以内に返信
-
getComputedStyle ignores a rule whose selector list contains a pseudo-element (regression in 30.x)対応中かも @chiragjangiir が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
chrisparsons83/flexspotff#215 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信