From 4b3c0d00dbeae5630a25cae69780caf47a9c5831 Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Wed, 26 Feb 2014 22:49:30 -0800 Subject: [PATCH 1/3] Write specs for entries that contain spaces --- spec/filter-spec.coffee | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/filter-spec.coffee b/spec/filter-spec.coffee index a190939..8bae8d7 100644 --- a/spec/filter-spec.coffee +++ b/spec/filter-spec.coffee @@ -31,3 +31,12 @@ describe "filtering", -> it "does not throw an exception", -> candidates = ['/'] expect(filter(candidates, 'bar', maxResults: 1)).toEqual [] + + describe "when the entries contains spaces", -> + it "treats spaces as slashes", -> + candidates = ['/bar/foo', '/foo/bar'] + expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/bar/foo'] + + it "weighs basename matches higher", -> + candidates = ['/bar/foo', '/foo/bar foo'] + expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/foo/bar foo'] From 274946e5738839cc4cf0a33f1addef9477663385 Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Wed, 26 Feb 2014 23:00:25 -0800 Subject: [PATCH 2/3] Add another example expectation --- spec/filter-spec.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/filter-spec.coffee b/spec/filter-spec.coffee index 8bae8d7..8cf0d43 100644 --- a/spec/filter-spec.coffee +++ b/spec/filter-spec.coffee @@ -40,3 +40,5 @@ describe "filtering", -> it "weighs basename matches higher", -> candidates = ['/bar/foo', '/foo/bar foo'] expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/foo/bar foo'] + candidates = ['/barfoo/foo', '/foo/barfoo'] + expect(filter(candidates, 'br f', maxResults: 1)).toEqual ['/foo/barfoo'] From 31f2dae7e0a021941b1ca4a5f8f00fa0af94027e Mon Sep 17 00:00:00 2001 From: Andrew McCloud Date: Wed, 26 Feb 2014 22:54:20 -0800 Subject: [PATCH 3/3] Remove spaces from query --- src/filter.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/filter.coffee b/src/filter.coffee index 5861d9d..58dbe6b 100644 --- a/src/filter.coffee +++ b/src/filter.coffee @@ -32,6 +32,7 @@ basenameScore = (string, query, score) -> module.exports = (candidates, query, {key, maxResults}={}) -> if query queryHasNoSlashes = query.indexOf('/') is -1 + query = query.replace(/\ /g, '') scoredCandidates = [] for candidate in candidates string = if key? then candidate[key] else candidate