Commit 5e5a45c4 authored by greebie's avatar greebie

Remove unnecessary valid query test.

URL queries should now use uri encoded strings for all default filter queries.
parent 8f725ae6
......@@ -15,13 +15,14 @@ function extractAnnotationQuery(url) {
var annotFragmentMatch = url.match(/#annotations:([A-Za-z0-9_-]+)$/);
var queryFragmentMatch = url.match(/#annotations:(query|q):(.+)$/i);
if (queryFragmentMatch) {
filter.query = queryFragmentMatch[2];
filter.query = decodeURI(queryFragmentMatch[2]);
} else if (annotFragmentMatch) {
filter.annotations = annotFragmentMatch[1];
} else {
filter = null;
}
} catch (err) {
// URI Error should return the page unfiltered.
filter = null;
}
return filter;
......
'use strict';
var unroll = require('../../../shared/test/util').unroll;
var annotationIds = require('../extract-annotation-query');
describe('annotation queries', function () {
var annotation = annotationIds.extractAnnotationQuery('http://localhost:3000#annotations:alphanum3ric_-only');
var queryVarA = annotationIds.extractAnnotationQuery('http://localhost:3000#annotations:q:user:USERNAME');
var queryVarB = annotationIds.extractAnnotationQuery('http://localhost:3000#annotations:QuerY:user:USERNAME');
var invalid = annotationIds.extractAnnotationQuery('http://localhost:3000#annotations:\"TRYINGTOGETIN\";EVILSCRIPT()');
it ('accepts regular annotation id', function () {
assert.equal(annotation.annotations, 'alphanum3ric_-only');
});
it ('returns null for query when annotation id exists', function() {
assert.equal(annotation.query, null);
});
it ('returns null on invalid query / id', function() {
assert.equal(invalid, null);
});
it ('produces a null annotation when valid query exists', function () {
assert.equal(queryVarA.annotations, null);
it ('returns null on invalid fragment', function () {
assert.equal(annotationIds.extractAnnotationQuery(
'http://localhost:3000#annotations:\"TRYINGTOGETIN\");EVILSCRIPT()'),
null);
});
it ('accepts query style A ("q:")', function () {
assert.equal(queryVarA.query, 'user:USERNAME');
});
it ('accepts query style B ("query:")', function () {
assert.equal (queryVarB.query, 'user:USERNAME');
});
unroll('accepts annotation fragment from urls', function (testCase) {
assert.equal(annotationIds.extractAnnotationQuery(testCase.url).annotations, testCase.result);
}, [{
url: 'http://localhost:3000#annotations:alphanum3ric_-only',
result: 'alphanum3ric_-only',
},
]);
unroll('accepts query from annotation fragment', function(testCase) {
assert.equal(annotationIds.extractAnnotationQuery(testCase.url).query, testCase.result);
}, [{
url: 'http://localhost:3000#annotations:q:user:USERNAME',
result: 'user:USERNAME',
},
{
url: 'http://localhost:3000#annotations:QuerY:user:USERNAME',
result: 'user:USERNAME',
}, {
url: 'http://localhost:3000#annotations:q:user:USERNAME%20tag:KEYWORD',
result: 'user:USERNAME tag:KEYWORD',
}]);
});
......@@ -16,7 +16,6 @@ var uiConstants = require('../ui-constants');
var util = require('./util');
var validQuery = require('../util/validate-query');
/**
* Default starting tab.
......@@ -42,7 +41,7 @@ TAB_SORTKEYS_AVAILABLE[uiConstants.TAB_ORPHANS] = ['Newest', 'Oldest', 'Location
function initialSelection(settings) {
var selection = {};
if (settings.annotations && !validQuery(settings.query)) {
if (settings.annotations && !settings.query) {
selection[settings.annotations] = true;
}
return freeze(selection);
......@@ -84,7 +83,7 @@ function init(settings) {
// IDs of annotations that should be highlighted
highlighted: [],
filterQuery: validQuery(settings.query),
filterQuery: settings.query,
selectedTab: TAB_DEFAULT,
......
'use strict';
var queryUrl = require('../validate-query');
describe('queryUrl', function () {
var qURL;
var longqURL;
var trickyqURL;
var upperURL;
beforeEach(function () {
qURL = queryUrl('user:user_name');
longqURL = queryUrl('user:user_nameany:hello');
trickyqURL = queryUrl('user_bob__helloany:hello');
upperURL = queryUrl('something');
});
it ('returns false on a non-query', function () {
assert.equal(queryUrl({foo:'bar'}), null);
});
it('returns an annotation string as a query', function () {
assert.equal(qURL, 'user:user_name');
});
it('accepts longer queries', function () {
assert.equal(longqURL, 'user:user_name any: hello');
});
it ('is not tricked by confounding usernames or queries', function() {
assert.equal(trickyqURL, 'user_bob__hello any: hello');
});
it ('accepts upper and lower case values', function () {
assert.equal(upperURL, 'something');
});
});
'use strict';
// A set of functions to prepare a query from a url request
//
// These functions take values from var annotations
// produced in a url fragment
// ( e.g. http://www.example.com/path/to/file
// #annotations:query__user__username)
// in settings
// and converts it to a search query, detecting
// tags like "user:", "any:" and "tag:".
//
function returnQueryFromAnnotationFragment (query){
var result = null;
try {
if (query) {
result = query.replace(/(user|any|tag|text):/gi,
function (tag) {
// temporarily fix bug where
// any:term does not work
if (tag === 'any:') {
return ' ' + tag + ' ';
} else {
return ' ' + tag;
}
}).trim();
}
} catch (e) {
result = null;
}
return (result);
}
module.exports = returnQueryFromAnnotationFragment;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment