denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
93.9k stars 5.22k forks source link

URLPattern with search parameters and base url doesn't work #24266

Closed irustm closed 1 month ago

irustm commented 2 months ago

Version: Deno 1.41, 1.44

deno repl   
Deno 1.44.2

> const p = new URLPattern("/api/data/", "http://localhost:8000")
p.exec("http://localhost:8000/api/data/?w=1&g=2")

null
// Chrome 126.0.6478.62

const p = new URLPattern("/api/data/", "http://localhost:8000")
p.exec("http://localhost:8000/api/data/?w=1&g=2")

{Object}

Deno 1.44.2
exit using ctrl+d, ctrl+c, or close()
> const pattern = new URLPattern("/books/:id(\\d+)", "https://example.com");
console.log(pattern.test("https://example.com/books/123"))
true
console.log(pattern.test("https://example.com/books/123?d=1"))
false
// Chrome 126.0.6478.62

const pattern = new URLPattern("/books/:id(\\d+)", "https://example.com");
console.log(pattern.test("https://example.com/books/123"))
true
console.log(pattern.test("https://example.com/books/123?d=1"))
true
yazan-abdalrahman commented 1 month ago

@irustm ,

Hi, I'm new to Deno. Could you give me more information on this issue, including how to reproduce it and what is expected result?

yazan-abdalrahman commented 1 month ago

the issue when exec query in deno its return null ? image image but it works in chrome right?

yazan-abdalrahman commented 1 month ago

@lucacasonato @bartlomieju , I found the issue in building the URLPattern in deno it set the default value of search as None and in another fields, it put empty string, and I founded in chrome it but wildcard () so I added a code to add wildcard () when defaults None or empty.

// in chrome image

// before set default value of search field as wildcard (*) image

// after set default value of search field as wildcard (*) image

But I still don't know where I can add tests for the code that I pushed. Please let me know where I can add tests for it.