mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-29 11:21:40 +02:00
Multikeys filter should allow nested names, ignore alt prefixes
This commit is contained in:
@@ -69,9 +69,12 @@ function filterKeys(type) {
|
||||
}
|
||||
|
||||
|
||||
function filterMultikeys() {
|
||||
function filterMultikeys(prefix) {
|
||||
return function(d) {
|
||||
return (d.key.match(/:/g) || []).length === 1; // exactly one ':'
|
||||
// d.key begins with prefix, and d.key contains no additional ':'s
|
||||
var re = new RegExp('^' + prefix + '(.*)$');
|
||||
var matches = d.key.match(re) || [];
|
||||
return (matches.length === 2 && matches[1].indexOf(':') === -1);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -177,6 +180,7 @@ export default {
|
||||
multikeys: function(parameters, callback) {
|
||||
var debounce = parameters.debounce;
|
||||
parameters = clean(setSort(parameters));
|
||||
var prefix = parameters.query;
|
||||
request(endpoint + 'keys/all?' +
|
||||
utilQsString(_.extend({
|
||||
rp: 25,
|
||||
@@ -187,7 +191,7 @@ export default {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
var f = filterMultikeys();
|
||||
var f = filterMultikeys(prefix);
|
||||
callback(null, d.data.filter(f).map(valKey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,15 +102,28 @@ describe('iD.serviceTaginfo', function() {
|
||||
|
||||
it('excludes multikeys with extra colons', function() {
|
||||
var callback = sinon.spy();
|
||||
taginfo.multikeys({query: 'recycling:'}, callback);
|
||||
taginfo.multikeys({query: 'service:bicycle:'}, callback);
|
||||
|
||||
server.respondWith('GET', new RegExp('https://taginfo.openstreetmap.org/api/4/keys/all'),
|
||||
[200, { 'Content-Type': 'application/json' },
|
||||
'{"data":[{"count_all":69593,"key":"recycling:glass","count_all_fraction":0.0},'
|
||||
+ '{"count_all":22,"key":"recycling:glass:color","count_all_fraction":0.0}]}']);
|
||||
'{"data":[{"count_all":4426,"key":"service:bicycle:retail","count_all_fraction":0.0},'
|
||||
+ '{"count_all":22,"key":"service:bicycle:retail:ebikes","count_all_fraction":0.0}]}']);
|
||||
server.respond();
|
||||
|
||||
expect(callback).to.have.been.calledWith(null, [{'title':'recycling:glass', 'value':'recycling:glass'}]);
|
||||
expect(callback).to.have.been.calledWith(null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}]);
|
||||
});
|
||||
|
||||
it('excludes multikeys with wrong prefix', function() {
|
||||
var callback = sinon.spy();
|
||||
taginfo.multikeys({query: 'service:bicycle:'}, callback);
|
||||
|
||||
server.respondWith('GET', new RegExp('https://taginfo.openstreetmap.org/api/4/keys/all'),
|
||||
[200, { 'Content-Type': 'application/json' },
|
||||
'{"data":[{"count_all":4426,"key":"service:bicycle:retail","count_all_fraction":0.0},'
|
||||
+ '{"count_all":22,"key":"disused:service:bicycle","count_all_fraction":0.0}]}']);
|
||||
server.respond();
|
||||
|
||||
expect(callback).to.have.been.calledWith(null, [{'title':'service:bicycle:retail', 'value':'service:bicycle:retail'}]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user