From 7e39b79eb6d7788a0870c547a62f76e154065a25 Mon Sep 17 00:00:00 2001 From: Leon van Kammen Date: Thu, 4 Apr 2024 16:48:39 +0000 Subject: [PATCH] work in progress [might break] --- src/Test.hx | 30 ++++++++++-------------------- src/spec/url.json | 3 ++- src/xrfragment/URL.hx | 17 ++++++++++------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/Test.hx b/src/Test.hx index 1472f62..9ced177 100644 --- a/src/Test.hx +++ b/src/Test.hx @@ -45,7 +45,9 @@ class Test { if( item.expect.fn == "testPropertyAssign" ) valid = res.exists(item.expect.input) && item.expect.out == res.get(item.expect.input).is( XRF.PROP_BIND) ; if( item.expect.fn == "testBrowserOverride" ) valid = item.expect.out == (URI.parse(item.data,XRF.NAVIGATOR)).exists(item.expect.input); if( item.expect.fn == "testEmbedOverride" ) valid = item.expect.out == (URI.parse(item.data,XRF.METADATA)).exists(item.expect.input); - if( item.expect.fn == "testURL" ) valid = testURL( item.data, item.expect.input, item.expect.out ); + if( item.expect.fn == "testURL" ) valid = testURL( item.data, item.expect.input, item.expect.out, false ); + if( item.expect.fn == "testURLHash" ) valid = testURL( item.data, item.expect.input, item.expect.out, false ); + if( item.expect.fn == "testURLBrowse" ) valid = testURL( item.data, item.expect.input, item.expect.out, true ); if( item.expect.fn == "equal.string" ) valid = res.get(item.expect.input) && item.expect.out == res.get(item.expect.input).string; if( item.expect.fn == "equal.x" ) valid = equalX(res,item); @@ -86,25 +88,13 @@ class Test { static public function testURL( url:String, attr:String, output:String, browserMode: Bool = false): Bool { var URL = xrfragment.URL; var url = URL.parse(url,false); - trace("url:"+url.url); - trace("source:"+url.source); - trace("scheme:"+url.scheme); - trace("auth:"+url.authority); - trace("uinfo:"+url.userInfo); - trace("u:"+url.user); - trace("pw:"+url.password); - trace("host:"+url.host); - trace("port:"+url.port); - trace("relative:"+url.relative); - trace("path:"+url.path); - trace("directory:"+url.directory); - trace("file:"+url.file); - trace("query:"+url.query); - trace("browserMode:"+url.browserMode); - trace("fragment:"+url.fragment); - trace("hash:"+url.hash); - if( Reflect.hasField(url, attr) && Reflect.field(url,attr) == output ) return true; - return false; + var parts:Array = attr.split("."); + if( parts.length > 1 && parts[0] == "hash" && url.hash.exists( parts[1]) ){ + return url.hash.get( parts[1] ) == output; + }else{ + if( Reflect.hasField(url, attr) && Reflect.field(url,attr) == output ) return true; + } + return false; } static public function testFilter():Void { diff --git a/src/spec/url.json b/src/spec/url.json index e22466d..8511077 100644 --- a/src/spec/url.json +++ b/src/spec/url.json @@ -4,5 +4,6 @@ {"fn":"url","data":"http://foo.com?foo=1#mypredefinedview&another", "expect":{ "fn":"testPredefinedView", "input":"mypredefinedview","out":true},"label":"test predefined view executed (multiple)"}, {"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testParsed", "input":"mycustom","out":true},"label":"test custom property"}, {"fn":"url","data":"http://foo.com?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"scheme","out":"http"},"label":"test URL scheme http"}, - {"fn":"url","data":"http://foo.com/a/b?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"path","out":"/a/b"},"label":"test URL path /a/b"} + {"fn":"url","data":"http://foo.com/a/b?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"path","out":"/a/b"},"label":"test URL path /a/b"}, + {"fn":"url","data":"http://foo.com/a/b?foo=1#mycustom=foo", "expect":{ "fn":"testURL", "input":"hash.mycustom","out":"foo"},"label":"test URL hash #mycustom == foo"} ] diff --git a/src/xrfragment/URL.hx b/src/xrfragment/URL.hx index 2782608..158fbf9 100644 --- a/src/xrfragment/URL.hx +++ b/src/xrfragment/URL.hx @@ -52,6 +52,7 @@ class URL public var browserMode: Bool; public var fragment : String; public var hash : haxe.DynamicAccess; + public var XRF : haxe.DynamicAccess; /** * class constructor @@ -77,7 +78,6 @@ class URL var url:URL = new URL(); url.browserMode = browserMode; - trace(url); // Use reflection to set each part for (i in 0..._parts.length) @@ -95,17 +95,20 @@ class URL } } + url.hash = {}; if( url.fragment.length > 0 ){ - trace("ja"); - url.hash = xrfragment.URI.parse( url.fragment, 0 ); - trace(url.hash.get('mycustom')); - }else url.hash = {}; - + url.XRF = xrfragment.URI.parse( "#"+url.fragment, 0 ); + var key:String; + for( key in url.XRF.keys() ){ + var v:haxe.DynamicAccess = url.XRF.get(key); + url.hash[key] = v.get("string"); + } + } return url; } /** - * Serialize an URL object into an + * Serialize an URl OBJect into an * URL string */ public static function toString(url:URL):String