nodejs / nodejs/node

url: URLPattern rejects values requiring WebIDL USVString conversion for input and baseURL

オープン
#64,785 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Version

latest main branch

Platform
7.1.4-arch1-1
Subsystem

url

What steps will reproduce the bug?

  const { URL, URLPattern } = require('node:url');

  const base = 'https://example.com/';
  const numberPattern =
    new URLPattern('https://example.com/123');
  const fooPattern =
    new URLPattern('https://example.com/foo');

  const baseObject = {
    toString() {
      return base;
    },
  };

  const baseURLObject = new URL(base);

  function observe(label, callback) {
    try {
      console.log(label, callback());
    } catch (error) {
      console.log(label, error.code, error.name);
    }
  }

  // URLPatternInput conversion.
  observe(
    'constructor input:',
    () => new URLPattern(123, base).pathname,
  );

  observe(
    'test input:',
    () => numberPattern.test(123, base),
  );

  observe(
    'exec input:',
    () => numberPattern.exec(123, base) !== null,
  );

  // baseURL conversion. The three-argument constructor is intentional:
  // it unambiguously selects the baseURL overload.
  observe(
    'constructor baseURL:',
    () => new URLPattern('foo', baseObject, {}).pathname,
  );

  observe(
    'test baseURL:',
    () => fooPattern.test('foo', baseURLObject),
  );

  observe(
    'exec baseURL:',
    () => fooPattern.exec('foo', baseURLObject) !== null,
  );
How often does it reproduce? Is there a required condition?

Every

What is the expected behavior? Why is that the expected behavior?
  constructor input: /123
  test input: true
  exec input: true
  constructor baseURL: /foo
  test baseURL: true
  exec baseURL: true
What do you see instead?

Each case throws a TypeError with code === 'ERR_INVALID_ARG_TYPE'.

Additional information

The URL Pattern IDL (https://urlpattern.spec.whatwg.org/#urlpattern) defines:

typedef (USVString or URLPatternInit) URLPatternInput;

constructor(
URLPatternInput input,
USVString baseURL,
optional URLPatternOptions options = {}
);

constructor(
optional URLPatternInput input = {},
optional URLPatternOptions options = {}
);

boolean test(
optional URLPatternInput input = {},
optional USVString baseURL
);

URLPatternResult? exec(
optional URLPatternInput input = {},
optional USVString baseURL
);

WebIDL requires JavaScript values assigned to USVString to undergo USVString conversion
(https://webidl.spec.whatwg.org/#es-USVString), rather than already being JavaScript String values.

The constructor must first perform WebIDL overload resolution (https://webidl.spec.whatwg.org/#dfn-overload-resolution-algorithm).

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

node:url URLPattern コンストラクター、test()、exec() のエントリーポイントから始め、次に最新の main ブランチに対して再現手順を実行します。引数の処理を、引用されている WebIDL のオーバーロード解決および USVString のルールと比較します。数値入力と object baseURL 値が ERR_INVALID_ARG_TYPE ではなく期待どおりの結果を生成し、示されたケースのリグレッションカバレッジがあることを完了条件とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, nodejs
領域
api, backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

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

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