diff options
| -rw-r--r-- | src/html/catom.nim | 16 | ||||
| -rw-r--r-- | src/html/dom.nim | 60 | ||||
| -rw-r--r-- | src/server/buffer.nim | 8 | ||||
| -rw-r--r-- | test/js/array_proto_at.html | 4 | ||||
| -rw-r--r--[l---------] | test/js/asserts.js | 24 | ||||
| -rw-r--r-- | test/js/base64.html | 48 | ||||
| -rw-r--r-- | test/js/class.html | 4 | ||||
| -rw-r--r-- | test/js/collection.html | 16 | ||||
| -rw-r--r-- | test/js/documentall.html | 8 | ||||
| -rw-r--r-- | test/js/element.html | 2 | ||||
| -rw-r--r-- | test/js/encode_decode.html | 4 | ||||
| -rw-r--r-- | test/js/headers.html | 6 | ||||
| -rw-r--r-- | test/js/htmlcollection.html | 8 | ||||
| -rw-r--r-- | test/js/hyperlink.html | 24 | ||||
| -rw-r--r-- | test/js/outerhtml.html | 2 | ||||
| -rw-r--r-- | test/js/reflect.html | 10 | ||||
| -rw-r--r-- | test/js/text.html | 2 | ||||
| -rw-r--r-- | test/js/title.html | 2 | ||||
| -rw-r--r-- | test/js/url.html | 94 | ||||
| -rw-r--r-- | test/js/window.html | 8 |
20 files changed, 220 insertions, 130 deletions
diff --git a/src/html/catom.nim b/src/html/catom.nim index c0263d95..8ac023ab 100644 --- a/src/html/catom.nim +++ b/src/html/catom.nim @@ -47,7 +47,10 @@ macro makeStaticAtom = satFormaction = "formaction" satFormenctype = "formenctype" satFormmethod = "formmethod" + satHash = "hash" satHeight = "height" + satHost = "host" + satHostname = "hostname" satHref = "href" satId = "id" satIntegrity = "integrity" @@ -67,13 +70,19 @@ macro makeStaticAtom = satNovalidate = "novalidate" satOnclick = "onclick" satOnload = "onload" + satOrigin = "origin" + satPassword = "password" + satPathname = "pathname" + satPort = "port" satProgress = "progress" + satProtocol = "protocol" satReadystatechange = "readystatechange" satReferrerpolicy = "referrerpolicy" satRel = "rel" satRequired = "required" satRows = "rows" satRowspan = "rowspan" + satSearch = "search" satSelected = "selected" satSize = "size" satSizes = "sizes" @@ -90,6 +99,7 @@ macro makeStaticAtom = satTouchstart = "touchstart" satType = "type" satUsemap = "usemap" + satUsername = "username" satValign = "valign" satValue = "value" satWheel = "wheel" @@ -220,6 +230,12 @@ proc fromJS*(ctx: JSContext; val: JSAtom; res: var CAtom): Opt[void] = res = ctx.getFactoryImpl().toAtom(s) return ok() +proc fromJS*(ctx: JSContext; val: JSAtom; res: var StaticAtom): Opt[void] = + var ca: CAtom + ?ctx.fromJS(val, ca) + res = ctx.getFactoryImpl().toStaticAtom(ca) + return ok() + proc toJS*(ctx: JSContext; atom: CAtom): JSValue = return ctx.toJS(ctx.getFactoryImpl().toStr(atom)) diff --git a/src/html/dom.nim b/src/html/dom.nim index 21f3f8dd..02343937 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2617,13 +2617,31 @@ proc parseColor(element: Element; s: string): ARGBColor = return color.argb # HTMLHyperlinkElementUtils (for <a> and <area>) -proc href0(element: HTMLElement): string = - if not element.attrb(satHref): - return "" - let url = parseURL(element.attr(satHref), some(element.document.baseURL)) - if url.isSome: - return $url.get - return "" +proc reinitURL*(element: HTMLElement): Option[URL] = + if element.attrb(satHref): + let url = parseURL(element.attr(satHref), some(element.document.baseURL)) + if url.isSome and url.get.scheme != "blob": + return url + return none(URL) + +proc hyperlinkGetProp(ctx: JSContext; element: HTMLElement; a: JSAtom): + JSValue = + let href = element.reinitURL() + var res = JS_NULL + var ca: StaticAtom + if ctx.fromJS(a, ca).isSome: + if ca in {satHref, satOrigin, satProtocol, satUsername, satPassword, + satHost, satHostname, satPort, satPathname, satSearch, satHash}: + if href.isSome: + let url = ctx.toJS(href.get) + if not JS_IsException(url): + res = JS_GetProperty(ctx, url, a) + JS_FreeValue(ctx, url) + elif ca == satProtocol: + res = ctx.toJS(":") + else: + res = ctx.toJS("") + return res # <base> proc href(base: HTMLBaseElement): string {.jsfget.} = @@ -2634,27 +2652,35 @@ proc href(base: HTMLBaseElement): string {.jsfget.} = return "" # <a> -proc href*(anchor: HTMLAnchorElement): string {.jsfget.} = - return anchor.href0 - proc setHref(anchor: HTMLAnchorElement; href: string) {.jsfset: "href".} = anchor.attr(satHref, href) -proc `$`(anchor: HTMLAnchorElement): string {.jsfunc.} = - return anchor.href +proc getter(ctx: JSContext; anchor: HTMLAnchorElement; a: JSAtom): JSValue + {.jsgetprop.} = + return ctx.hyperlinkGetProp(anchor, a) + +proc toString(anchor: HTMLAnchorElement): string {.jsfunc.} = + let href = anchor.reinitURL() + if href.isSome: + return $href.get + return "" proc setRelList(anchor: HTMLAnchorElement; s: string) {.jsfset: "relList".} = anchor.attr(satRel, s) # <area> -proc href(area: HTMLAreaElement): string {.jsfget.} = - return area.href0 - proc setHref(area: HTMLAreaElement; href: string) {.jsfset: "href".} = area.attr(satHref, href) -proc `$`(area: HTMLAreaElement): string {.jsfunc.} = - return area.href +proc getter(ctx: JSContext; anchor: HTMLAreaElement; a: JSAtom): JSValue + {.jsgetprop.} = + return ctx.hyperlinkGetProp(anchor, a) + +proc toString(area: HTMLAreaElement): string {.jsfunc.} = + let href = area.reinitURL() + if href.isSome: + return $href.get + return "" proc setRelList(area: HTMLAreaElement; s: string) {.jsfset: "relList".} = area.attr(satRel, s) diff --git a/src/server/buffer.nim b/src/server/buffer.nim index 2de57c85..246e0c64 100644 --- a/src/server/buffer.nim +++ b/src/server/buffer.nim @@ -338,7 +338,7 @@ proc isClickable(styledNode: StyledNode): bool = return false let element = Element(styledNode.node) if element of HTMLAnchorElement: - return HTMLAnchorElement(element).href != "" + return HTMLAnchorElement(element).reinitURL().isSome if element.isButton() and FormAssociatedElement(element).form == nil: return false return element.tagType in ClickableElements @@ -370,7 +370,9 @@ proc getClickHover(buffer: Buffer; styledNode: StyledNode): string = let clickable = styledNode.getClickable() if clickable != nil: if clickable of HTMLAnchorElement: - return HTMLAnchorElement(clickable).href + let url = HTMLAnchorElement(clickable).reinitURL() + if url.isSome: + return $url.get elif clickable of FormAssociatedElement: #TODO this is inefficient and also quite stupid let fae = FormAssociatedElement(clickable) @@ -1420,7 +1422,7 @@ proc evalJSURL(buffer: Buffer; url: URL): Opt[string] = proc click(buffer: Buffer; anchor: HTMLAnchorElement): ClickResult = var repaint = buffer.restoreFocus() - let url = parseURL(anchor.href, some(buffer.baseURL)) + let url = anchor.reinitURL() if url.isSome: var url = url.get if url.scheme == "javascript": diff --git a/test/js/array_proto_at.html b/test/js/array_proto_at.html index 844aa563..e2ee9135 100644 --- a/test/js/array_proto_at.html +++ b/test/js/array_proto_at.html @@ -3,7 +3,7 @@ <script src=asserts.js></script> <script> assert(!![].at); -assert_equals([1, 2, 3].at(-2), 2); -assert_equals([1, 2, 3].at(-4), undefined); +assertEquals([1, 2, 3].at(-2), 2); +assertEquals([1, 2, 3].at(-4), undefined); document.getElementById("x").textContent = "Success"; </script> diff --git a/test/js/asserts.js b/test/js/asserts.js index 8471bc87..8a6171bc 120000..100644 --- a/test/js/asserts.js +++ b/test/js/asserts.js @@ -1 +1,23 @@ -../asserts.js
\ No newline at end of file +function assert(x, msg) { + const mymsg = msg ? ": " + msg : ""; + if (!x) + throw new TypeError("Assertion failed" + mymsg); +} + +function assertThrows(expr, error) { + try { + eval(expr); + } catch (e) { + if (e instanceof Error) + return; + } + throw new TypeError("Assertion failed"); +} + +function assertEquals(a, b) { + assert(a === b, "Expected " + b + " but got " + a); +} + +function assertInstanceof(a, b) { + assert(a instanceof b, a + " not an instance of " + b); +} diff --git a/test/js/base64.html b/test/js/base64.html index 0573d477..02a2364d 100644 --- a/test/js/base64.html +++ b/test/js/base64.html @@ -5,22 +5,22 @@ <script> const div = document.getElementById("x"); -assert_equals(atob(""), ""); -assert_equals(atob(" "), ""); -assert_equals(atob("YQ"), "a"); -assert_equals(atob("YR"), "a"); -assert_throws('atob("!")', DOMException); -assert_throws('atob("a")', DOMException); -assert_throws('atob("aaaaa")', DOMException); -assert_throws('atob("Aaa==")', DOMException); -assert_throws('atob("Aaaa==")', DOMException); -assert_throws('atob("Aaaaa==")', DOMException); -assert_throws('atob("Aa aaa= = ")', DOMException); -assert_equals(atob("AAAAAA=="), atob("AAAAAA")); -assert_equals(atob("AAAAAA"), atob("A A A A A A")); -assert_equals(atob("AAAAAA"), "\u0000\u0000\u0000\u0000"); -assert_equals(atob("ABCDEF"), "\u0000\u0010\u0083\u0010"); -assert_equals(atob("//////"), "ÿÿÿÿ"); +assertEquals(atob(""), ""); +assertEquals(atob(" "), ""); +assertEquals(atob("YQ"), "a"); +assertEquals(atob("YR"), "a"); +assertThrows('atob("!")', DOMException); +assertThrows('atob("a")', DOMException); +assertThrows('atob("aaaaa")', DOMException); +assertThrows('atob("Aaa==")', DOMException); +assertThrows('atob("Aaaa==")', DOMException); +assertThrows('atob("Aaaaa==")', DOMException); +assertThrows('atob("Aa aaa= = ")', DOMException); +assertEquals(atob("AAAAAA=="), atob("AAAAAA")); +assertEquals(atob("AAAAAA"), atob("A A A A A A")); +assertEquals(atob("AAAAAA"), "\u0000\u0000\u0000\u0000"); +assertEquals(atob("ABCDEF"), "\u0000\u0010\u0083\u0010"); +assertEquals(atob("//////"), "ÿÿÿÿ"); const longa = "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz" + "IHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2Yg" + @@ -32,13 +32,13 @@ const longb = "Man is distinguished, not only by his reason, but by this " + "that by a perseverance of delight in the continued and " + "indefatigable generation of knowledge, exceeds the short vehemence " + "of any carnal pleasure.\n"; -assert_equals(atob(longa), longb); -assert_equals(btoa(""), ""); -assert_equals(btoa("a"), "YQ=="); -assert_equals(btoa("aa"), "YWE="); -assert_equals(btoa("aaa"), "YWFh"); -assert_equals(btoa("aaazdxfksljdf"), "YWFhemR4ZmtzbGpkZg=="); -assert_equals(btoa(longb), longa); -assert_throws('btoa("őÉéeé")', DOMException); +assertEquals(atob(longa), longb); +assertEquals(btoa(""), ""); +assertEquals(btoa("a"), "YQ=="); +assertEquals(btoa("aa"), "YWE="); +assertEquals(btoa("aaa"), "YWFh"); +assertEquals(btoa("aaazdxfksljdf"), "YWFhemR4ZmtzbGpkZg=="); +assertEquals(btoa(longb), longa); +assertThrows('btoa("őÉéeé")', DOMException); div.textContent = "Success"; </script> diff --git a/test/js/class.html b/test/js/class.html index 5ee2f869..88972f13 100644 --- a/test/js/class.html +++ b/test/js/class.html @@ -7,11 +7,11 @@ const div = document.getElementsByClassName("a")[0] const classes = ["a", "b", "c"]; let cl = div.classList; for (let i = 0; i < classes.length; ++i) - assert_equals(cl[i], classes[i]); + assertEquals(cl[i], classes[i]); const classes2 = ["x", "y", "z"]; div.setAttribute("class", classes2.join(' ')); let i = 0; for (let x of cl) - assert_equals(x, classes2[i++]); + assertEquals(x, classes2[i++]); div.textContent = "Success"; </script> diff --git a/test/js/collection.html b/test/js/collection.html index 4f83875f..e02cbbad 100644 --- a/test/js/collection.html +++ b/test/js/collection.html @@ -9,15 +9,15 @@ <script> const x = document.getElementById("x"); const test = document.getElementById("test"); -assert_equals(document.forms[0], test); -assert_equals(document.forms["test"], test); +assertEquals(document.forms[0], test); +assertEquals(document.forms["test"], test); const elements = test.elements; -assert_equals(elements["a"], undefined); -assert_instanceof(elements[0], HTMLInputElement); -assert_equals(elements[0].id, "1"); -assert_equals(elements["0"].id, "1"); -assert_equals(elements[0].name, "input"); -assert_instanceof(elements["input"], RadioNodeList); +assertEquals(elements["a"], undefined); +assertInstanceof(elements[0], HTMLInputElement); +assertEquals(elements[0].id, "1"); +assertEquals(elements["0"].id, "1"); +assertEquals(elements[0].name, "input"); +assertInstanceof(elements["input"], RadioNodeList); let el = elements[0]; el.remove(); el.remove(); diff --git a/test/js/documentall.html b/test/js/documentall.html index c0272ca3..712796af 100644 --- a/test/js/documentall.html +++ b/test/js/documentall.html @@ -9,11 +9,11 @@ const abc = document.all; assert(!document.all, "document.all must be falsy"); assert(!abc, "document.all must be falsy"); -assert_equals(document.all.length, 10); +assertEquals(document.all.length, 10); const styles = [abc[6], abc[7], abc[8]]; -assert_equals(styles[0].textContent, "style 1"); -assert_equals(styles[1].textContent, "style 2"); -assert_equals(styles[2].textContent, "style 3"); +assertEquals(styles[0].textContent, "style 1"); +assertEquals(styles[1].textContent, "style 2"); +assertEquals(styles[2].textContent, "style 3"); const result = document.getElementById("result"); result.textContent = "Success"; </script> diff --git a/test/js/element.html b/test/js/element.html index cdbd91f7..179fbb1e 100644 --- a/test/js/element.html +++ b/test/js/element.html @@ -4,6 +4,6 @@ <script src=asserts.js></script> <script> const x = document.getElementById("x"); -assert(x.localName == "div"); +assertEquals(x.localName, "div"); x.textContent = "Success"; </script> diff --git a/test/js/encode_decode.html b/test/js/encode_decode.html index 82e9676c..c2bcd509 100644 --- a/test/js/encode_decode.html +++ b/test/js/encode_decode.html @@ -19,7 +19,7 @@ function bytesToBase64(bytes) { const utf8 = new TextEncoder().encode("a Ā 𐀀 文 🦄") const b64utf8 = bytesToBase64(utf8); -assert_equals(b64utf8, "YSDEgCDwkICAIOaWhyDwn6aE") +assertEquals(b64utf8, "YSDEgCDwkICAIOaWhyDwn6aE") const dec = new TextDecoder(); const bytes = base64ToBytes(b64utf8); const a = []; @@ -27,6 +27,6 @@ let res = ""; for (const c of bytes) res += dec.decode(c, {stream: true}); res += dec.decode(); -assert_equals(res, "a Ā 𐀀 文 🦄"); +assertEquals(res, "a Ā 𐀀 文 🦄"); document.getElementById("success").textContent = "Success"; </script> diff --git a/test/js/headers.html b/test/js/headers.html index ef836f40..b52df86c 100644 --- a/test/js/headers.html +++ b/test/js/headers.html @@ -5,8 +5,8 @@ <script> const x = new Headers(); x.append("hi", "world"); -assert_equals(x.get("hi"), "world"); -assert_equals(x.get("Hi"), "world"); -assert_equals(x.get("hI"), "world"); +assertEquals(x.get("hi"), "world"); +assertEquals(x.get("Hi"), "world"); +assertEquals(x.get("hI"), "world"); document.getElementById("x").textContent = "Success"; </script> diff --git a/test/js/htmlcollection.html b/test/js/htmlcollection.html index 2b5b4983..e52dbadd 100644 --- a/test/js/htmlcollection.html +++ b/test/js/htmlcollection.html @@ -7,13 +7,13 @@ <script src=asserts.js></script> <script> const abc = document.getElementsByClassName("abc"); -assert_equals(abc.length, 1); +assertEquals(abc.length, 1); abc[0].className = "defg"; -assert_equals(abc.length, 0); +assertEquals(abc.length, 0); const styles = document.getElementsByTagName("style"); -assert_equals(styles.length, 3); +assertEquals(styles.length, 3); for (let i = 0; i < styles.length; ++i) - assert_equals(styles[i].textContent, "style " + i); + assertEquals(styles[i].textContent, "style " + i); for (const style of styles) style.remove(); const defg = document.getElementsByClassName("defg"); diff --git a/test/js/hyperlink.html b/test/js/hyperlink.html new file mode 100644 index 00000000..92a1d674 --- /dev/null +++ b/test/js/hyperlink.html @@ -0,0 +1,24 @@ +<!doctype html> +<title>Test template</title> +<a id=invalid>invalid</a> +<a id=valid href='https://username:password@example.org/path?search#hash'>valid</a> +<div id=x>Fail</div> +<script src=asserts.js></script> +<script> +const invalid = document.getElementById("invalid"); +assertEquals(invalid.href, ""); +assertEquals(invalid.protocol, ":"); +assertEquals(invalid.search, ""); +assertEquals(invalid.hostname, ""); +assertEquals(invalid.hash, ""); +const valid = document.getElementById("valid"); +const url = new URL("https://username:password@example.org/path?search#hash"); +assertEquals(valid.protocol, "https:"); +for (const x in ["href", "origin", "protocol", "username", "password", "host", + "hostname", "port", "pathname", "search", "hash"]) { + assertEquals(valid[x], url[x]); +} +invalid.remove(); +valid.remove(); +document.getElementById("x").textContent = "Success"; +</script> diff --git a/test/js/outerhtml.html b/test/js/outerhtml.html index 8e4bbd2c..91861f0d 100644 --- a/test/js/outerhtml.html +++ b/test/js/outerhtml.html @@ -4,6 +4,6 @@ <script src=asserts.js></script> <script> const div = document.getElementById("test"); -assert_equals(div.outerHTML, '<div id="test">Fail</div>'); +assertEquals(div.outerHTML, '<div id="test">Fail</div>'); div.textContent = "Success"; </script> diff --git a/test/js/reflect.html b/test/js/reflect.html index 9b2ed4cb..78f59551 100644 --- a/test/js/reflect.html +++ b/test/js/reflect.html @@ -5,13 +5,13 @@ <script> const x = document.getElementById("abc") const a = document.getElementsByTagName("a")[0]; -assert_equals(a.target, "abcd"); +assertEquals(a.target, "abcd"); a.target = "defg"; -assert_equals(a.target, "defg"); -assert_equals(a.relList + "", ""); +assertEquals(a.target, "defg"); +assertEquals(a.relList + "", ""); a.relList = "..."; -assert_equals(a.relList + "", "..."); -assert_equals(a.className, "claz"); +assertEquals(a.relList + "", "..."); +assertEquals(a.className, "claz"); x.textContent = "Success"; a.remove(); /* ignore target... */ </script> diff --git a/test/js/text.html b/test/js/text.html index 8a511868..c2688bfb 100644 --- a/test/js/text.html +++ b/test/js/text.html @@ -2,6 +2,6 @@ <div id=x>Fail</div> <script src=asserts.js></script> <script> -assert_equals(new Text("data").ownerDocument, document); +assertEquals(new Text("data").ownerDocument, document); document.getElementById("x").textContent = "Success"; </script> diff --git a/test/js/title.html b/test/js/title.html index f364f3c6..528562fc 100644 --- a/test/js/title.html +++ b/test/js/title.html @@ -5,6 +5,6 @@ <div id=x>Fail</div> <script src=asserts.js></script> <script> -assert_equals(document.title, "Title test"); +assertEquals(document.title, "Title test"); document.getElementById("x").textContent = "Success"; </script> diff --git a/test/js/url.html b/test/js/url.html index b9ea2766..265cbbf9 100644 --- a/test/js/url.html +++ b/test/js/url.html @@ -3,70 +3,70 @@ <div id=x>Fail</div> <script src=asserts.js></script> <script> -assert_equals(new URL("https:example.org") + "", "https://example.org/"); -assert_equals(new URL("https://////example.com///") + "", "https://example.com///"); -assert_equals(new URL("https://example.com/././foo") + "", "https://example.com/foo"); -assert_equals(new URL("hello:world", "https://example.com/") + "", "hello:world"); -assert_equals(new URL("https:example.org", "https://example.com/") + "", "https://example.com/example.org"); -assert_equals(new URL(String.raw`\example\..\demo/.\ `, "https://example.com/") + "", "https://example.com/demo/"); -assert_equals(new URL("example", "https://example.com/demo") + "", "https://example.com/example"); -assert_equals(new URL('file:///C|/demo') + "", "file:///C:/demo"); -assert_equals(new URL('..', 'file:///C:/demo') + "", "file:///C:/"); -assert_equals(new URL('file://loc%61lhost/') + "", "file:///"); -assert_equals(new URL("https://user:password@example.org/") + "", "https://user:password@example.org/"); -assert_equals(new URL("https://example.org/foo bar") + "", "https://example.org/foo%20bar"); -assert_equals(new URL("https://EXAMPLE.com/../x") + "", "https://example.com/x"); -assert_throws('new URL("https://ex ample.org/")'); -assert_throws('new URL("example")'); -assert_throws('new URL("https://example.com:demo")'); -assert_throws('new URL("https://[www.example.com]")'); -assert_equals(new URL("https://example.org//") + "", "https://example.org//"); -assert_equals(new URL("https://example.com/[]?[]#[]") + "", "https://example.com/[]?[]#[]"); -assert_equals(new URL("https://example/%?%#%") + "", "https://example/%?%#%"); -assert_equals(new URL("https://example/%25?%25#%25") + "", "https://example/%25?%25#%25"); -assert_throws('new URL("https:example\r.org")'); -assert_equals(new URL(" https:exa\tmple\n.org\n/ ") + "", "https://example.org/"); -assert_equals(new URL(" https:exa\tmple.org\n:\n2\n4\n5\n2\n\n/ ") + "", "https://example.org:2452/"); -assert_equals(new URL(" h\nt\tt\np\ts\n:\t/\n/\te\nx\ta\nm\tp\nl\te\n/\tp\na\tt\n\nh\t?\nq\tu\ne\tr\ny\t#\nf\tr\na\tg\nm\te\nnt") + "", "https://example/path?query#fragment"); -assert_equals(new URL(" h\nt\tt\np\ts\n:\t/\n/\tu\ns\ne\nr\nn\na\n\nm\ne\n:\np\na\ns\ns\nw\no\nr\nd\n@\ne\nx\ta\nm\tp\nl\te\n/\tp\na\tt\n\nh\t?\nq\tu\ne\tr\ny\t#\nf\tr\na\tg\nm\te\nnt") + "", "https://username:password@example/path?query#fragment"); -assert_equals(new URL("abcd?efgh", "https://example.com/") + "", "https://example.com/abcd?efgh"); -assert_equals(new URL("abcd#ijkl", "https://example.com/") + "", "https://example.com/abcd#ijkl"); -assert_equals(new URL("abcd?efgh#ijkl", "https://example.com/") + "", "https://example.com/abcd?efgh#ijkl"); -assert_equals(new URL("https://テスト") + "", "https://xn--zckzah/"); -assert_equals(new URL("https://xn--zckzah") + "", "https://xn--zckzah/"); -assert_throws('new URL("https://[]")'); +assertEquals(new URL("https:example.org") + "", "https://example.org/"); +assertEquals(new URL("https://////example.com///") + "", "https://example.com///"); +assertEquals(new URL("https://example.com/././foo") + "", "https://example.com/foo"); +assertEquals(new URL("hello:world", "https://example.com/") + "", "hello:world"); +assertEquals(new URL("https:example.org", "https://example.com/") + "", "https://example.com/example.org"); +assertEquals(new URL(String.raw`\example\..\demo/.\ `, "https://example.com/") + "", "https://example.com/demo/"); +assertEquals(new URL("example", "https://example.com/demo") + "", "https://example.com/example"); +assertEquals(new URL('file:///C|/demo') + "", "file:///C:/demo"); +assertEquals(new URL('..', 'file:///C:/demo') + "", "file:///C:/"); +assertEquals(new URL('file://loc%61lhost/') + "", "file:///"); +assertEquals(new URL("https://user:password@example.org/") + "", "https://user:password@example.org/"); +assertEquals(new URL("https://example.org/foo bar") + "", "https://example.org/foo%20bar"); +assertEquals(new URL("https://EXAMPLE.com/../x") + "", "https://example.com/x"); +assertThrows('new URL("https://ex ample.org/")'); +assertThrows('new URL("example")'); +assertThrows('new URL("https://example.com:demo")'); +assertThrows('new URL("https://[www.example.com]")'); +assertEquals(new URL("https://example.org//") + "", "https://example.org//"); +assertEquals(new URL("https://example.com/[]?[]#[]") + "", "https://example.com/[]?[]#[]"); +assertEquals(new URL("https://example/%?%#%") + "", "https://example/%?%#%"); +assertEquals(new URL("https://example/%25?%25#%25") + "", "https://example/%25?%25#%25"); +assertThrows('new URL("https:example\r.org")'); +assertEquals(new URL(" https:exa\tmple\n.org\n/ ") + "", "https://example.org/"); +assertEquals(new URL(" https:exa\tmple.org\n:\n2\n4\n5\n2\n\n/ ") + "", "https://example.org:2452/"); +assertEquals(new URL(" h\nt\tt\np\ts\n:\t/\n/\te\nx\ta\nm\tp\nl\te\n/\tp\na\tt\n\nh\t?\nq\tu\ne\tr\ny\t#\nf\tr\na\tg\nm\te\nnt") + "", "https://example/path?query#fragment"); +assertEquals(new URL(" h\nt\tt\np\ts\n:\t/\n/\tu\ns\ne\nr\nn\na\n\nm\ne\n:\np\na\ns\ns\nw\no\nr\nd\n@\ne\nx\ta\nm\tp\nl\te\n/\tp\na\tt\n\nh\t?\nq\tu\ne\tr\ny\t#\nf\tr\na\tg\nm\te\nnt") + "", "https://username:password@example/path?query#fragment"); +assertEquals(new URL("abcd?efgh", "https://example.com/") + "", "https://example.com/abcd?efgh"); +assertEquals(new URL("abcd#ijkl", "https://example.com/") + "", "https://example.com/abcd#ijkl"); +assertEquals(new URL("abcd?efgh#ijkl", "https://example.com/") + "", "https://example.com/abcd?efgh#ijkl"); +assertEquals(new URL("https://テスト") + "", "https://xn--zckzah/"); +assertEquals(new URL("https://xn--zckzah") + "", "https://xn--zckzah/"); +assertThrows('new URL("https://[]")'); { const x = new URL("file:/test"); x.protocol = "abcd"; - assert_equals(x.protocol, "file:"); + assertEquals(x.protocol, "file:"); } { const x = new URL("efgh:/test"); x.protocol = "abcd"; - assert_equals(x.protocol, "abcd:"); + assertEquals(x.protocol, "abcd:"); x.protocol = " efgh"; - assert_equals(x.protocol, "abcd:"); + assertEquals(x.protocol, "abcd:"); } { const x = new URL("http:/test"); x.protocol = "abcd"; - assert_equals(x.protocol, "http:"); + assertEquals(x.protocol, "http:"); x.protocol = "https"; - assert_equals(x.protocol, "https:"); + assertEquals(x.protocol, "https:"); } { const x = new URL("https://user:password@example.org:1234/path?search#hash"); - assert_equals(x.protocol, "https:"); - assert_equals(x.username, "user"); - assert_equals(x.password, "password"); - assert_equals(x.hostname, "example.org"); - assert_equals(x.port, "1234"); - assert_equals(x.host, "example.org:1234"); - assert_equals(x.pathname, "/path"); - assert_equals(x.search, "?search"); - assert_equals(x.hash, "#hash"); + assertEquals(x.protocol, "https:"); + assertEquals(x.username, "user"); + assertEquals(x.password, "password"); + assertEquals(x.hostname, "example.org"); + assertEquals(x.port, "1234"); + assertEquals(x.host, "example.org:1234"); + assertEquals(x.pathname, "/path"); + assertEquals(x.search, "?search"); + assertEquals(x.hash, "#hash"); x.searchParams.delete("search"); - assert_equals(x.search, ""); + assertEquals(x.search, ""); x.searchParams.append("hi", "world"); assert(x.searchParams.has("hi")); assert(x.searchParams.has("hi", "world")); diff --git a/test/js/window.html b/test/js/window.html index 07b76145..81485cad 100644 --- a/test/js/window.html +++ b/test/js/window.html @@ -3,16 +3,16 @@ <div id=x>Fail</div> <script src=asserts.js></script> <script> -assert_equals(window.toString(), "[object Window]"); +assertEquals(window.toString(), "[object Window]"); const desc = Object.getOwnPropertyDescriptor(window, "window"); assert(desc.enumerable, "window must be enumerable"); assert(!desc.configurable, "window must not be configurable"); -assert_equals(window.history.state, null); +assertEquals(window.history.state, null); window.localStorage.setItem("a", "x"); window.localStorage["b"] = "y"; -assert_equals(window.localStorage["b"], "y") +assertEquals(window.localStorage["b"], "y") delete window.localStorage.b; -assert_equals(window.localStorage["b"], undefined); +assertEquals(window.localStorage["b"], undefined); window.localStorage["b"] = "y"; assert(window.sessionStorage instanceof Storage); document.getElementById("x").textContent = "Success"; |