nodejs / nodejs/node

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

Đang mở
#64,785 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

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).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với các entry point của constructor node:url URLPattern, test() và exec(), sau đó chạy bản tái hiện trên branch main mới nhất. So sánh cách xử lý đối số với các quy tắc WebIDL về phân giải overload và USVString đã được dẫn chiếu. Được xem là hoàn tất khi đầu vào dạng số và các giá trị object baseURL tạo ra kết quả mong đợi thay vì ERR_INVALID_ARG_TYPE, với độ bao phủ hồi quy cho các trường hợp được nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, nodejs
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.