Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

SVG elements in an HTML document report an upper-cased tagName ("PATH" instead of "path")

オープン 初心者向け
#344 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

WebReflection/linkedom のほかの issue

WebReflection/linkedom の issue をすべて見る

似ている issue

Web Dev の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。