Ox.URL: fix and update tests

This commit is contained in:
rlx 2013-03-05 06:05:35 +00:00
parent d3f39c29f2
commit 35947ab77b

View file

@ -56,16 +56,23 @@ Ox.URL <f> URL controller
{id: 'population', type: 'integer'} {id: 'population', type: 'integer'}
], ],
getHash: function(state, callback) { getHash: function(state, callback) {
if ( if (state.hash) {
state.hash && state.hash.anchor if (state.hash.anchor == 'invalid') {
&& state.hash.anchor.length > 1
) {
if (state.hash.query) {
delete state.hash.anchor; 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; delete state.hash;
} }
} }
callback();
}, },
getItem: function(state, str, callback) { getItem: function(state, str, callback) {
state.item = /^\d+$/.test(str) ? str : ''; state.item = /^\d+$/.test(str) ? str : '';
@ -225,14 +232,6 @@ Ox.URL <f> URL controller
operator: '&' operator: '&'
} }
}, },
'/#?k=v&l=w': {
hash: {
query: [
{key: 'k', value: 'v'},
{key: 'l', value: 'w'}
]
}
},
'/#a?k=v&l=w': { '/#a?k=v&l=w': {
hash: { hash: {
anchor: 'a', anchor: 'a',
@ -242,7 +241,7 @@ Ox.URL <f> 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: { hash: {
query: [ query: [
{key: 'a', value: [1, 2]}, {key: 'a', value: [1, 2]},
@ -253,7 +252,8 @@ Ox.URL <f> URL controller
{key: 's2', value: 'bar'} {key: 's2', value: 'bar'}
] ]
} }
} },
'/#invalid?invalid=true': {}
}; };
</script> </script>
> !!Ox.test.url.parse('/', function(o) { Ox.test(o, Ox.test.result['/']); }) > !!Ox.test.url.parse('/', function(o) { Ox.test(o, Ox.test.result['/']); })
@ -284,11 +284,11 @@ Ox.URL <f> URL controller
true 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)']); }) > !!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 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']); }) > !!Ox.test.url.parse('/#a?k=v&l=w', function(o) { Ox.test(o, Ox.test.result['/#a?k=v&l=w']); })
true 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 true
@*/ @*/