From 35947ab77bda0632e4ecd32ff112a15921e4fb42 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Tue, 5 Mar 2013 06:05:35 +0000 Subject: [PATCH] Ox.URL: fix and update tests --- source/Ox.UI/js/Core/URL.js | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/source/Ox.UI/js/Core/URL.js b/source/Ox.UI/js/Core/URL.js index 648d321f..7e9f155f 100644 --- a/source/Ox.UI/js/Core/URL.js +++ b/source/Ox.UI/js/Core/URL.js @@ -56,16 +56,23 @@ Ox.URL URL controller {id: 'population', type: 'integer'} ], getHash: function(state, callback) { - if ( - state.hash && state.hash.anchor - && state.hash.anchor.length > 1 - ) { - if (state.hash.query) { + if (state.hash) { + if (state.hash.anchor == 'invalid') { delete state.hash.anchor; - } else { + } + if (state.hash.query) { + state.hash.query = state.hash.query.filter(function(v) { + return v.key != 'invalid' + }); + if (Ox.isEmpty(state.hash.query)) { + delete state.hash.query; + } + } + if (Ox.isEmpty(state.hash)) { delete state.hash; } } + callback(); }, getItem: function(state, str, callback) { state.item = /^\d+$/.test(str) ? str : ''; @@ -225,14 +232,6 @@ Ox.URL URL controller operator: '&' } }, - '/#?k=v&l=w': { - hash: { - query: [ - {key: 'k', value: 'v'}, - {key: 'l', value: 'w'} - ] - } - }, '/#a?k=v&l=w': { hash: { anchor: 'a', @@ -242,7 +241,7 @@ Ox.URL URL controller ] } }, - '/#invalid?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar': { + '/#?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar': { hash: { query: [ {key: 'a', value: [1, 2]}, @@ -253,7 +252,8 @@ Ox.URL URL controller {key: 's2', value: 'bar'} ] } - } + }, + '/#invalid?invalid=true': {} }; > !!Ox.test.url.parse('/', function(o) { Ox.test(o, Ox.test.result['/']); }) @@ -284,11 +284,11 @@ Ox.URL URL controller true > !!Ox.test.url.parse('/population>0&(name=a*|name=*z)', function(o) { Ox.test(o, Ox.test.result['/population>0&(name=a*|name=*z)']); }) true - > !!Ox.test.url.parse('/#?k=v&l=w', function(o) { Ox.test(o, Ox.test.result['/#?k=v&l=w']); }) - true > !!Ox.test.url.parse('/#a?k=v&l=w', function(o) { Ox.test(o, Ox.test.result['/#a?k=v&l=w']); }) true - > !!Ox.test.url.parse('/#invalid?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar', function(o) { Ox.test(o, Ox.test.result['/#invalid?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar']); }) + > !!Ox.test.url.parse('/#?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar', function(o) { Ox.test(o, Ox.test.result['/#?a=[1,2]&b=true&n=1.2&o={"k":"v"}&s1="foo"&s2=bar']); }) + true + > !!Ox.test.url.parse('/#invalid?invalid=true', function(o) { Ox.test(o, Ox.test.result['/#invalid?invalid=true']); }) true @*/