Flag and upgrade deprecated tags in a semicolon-delimited tag value (close #6038)

This commit is contained in:
Quincy Morgan
2019-03-11 10:22:28 -04:00
parent d9dfa2ff46
commit 93df5d42d9
3 changed files with 32 additions and 2 deletions

View File

@@ -8,8 +8,17 @@ export function actionUpgradeTags(entityId, oldTags, replaceTags) {
for (var oldTagKey in oldTags) {
if (oldTags[oldTagKey] === '*') {
transferValue = tags[oldTagKey];
delete tags[oldTagKey];
} else {
var vals = tags[oldTagKey].split(';').filter(Boolean);
var oldIndex = vals.indexOf(oldTags[oldTagKey]);
if (vals.length === 1 || oldIndex === -1) {
delete tags[oldTagKey];
} else {
vals.splice(oldIndex, 1);
tags[oldTagKey] = vals.join(';');
}
}
delete tags[oldTagKey];
}
if (replaceTags) {
for (var replaceKey in replaceTags) {

View File

@@ -173,7 +173,12 @@ osmEntity.prototype = {
var deprecated = [];
dataDeprecated.forEach(function(d) {
var matchesDeprecatedTags = _every(Object.keys(d.old), function(key) {
return tags[key] && (d.old[key] === tags[key] || d.old[key] === '*');
if (!tags[key]) return false;
if (d.old[key] === '*') return true;
var vals = tags[key].split(';').filter(Boolean);
if (!vals.length) return false;
return vals.indexOf(d.old[key]) !== -1;
});
if (matchesDeprecatedTags) {
deprecated.push(d);

View File

@@ -56,4 +56,20 @@ describe('iD.actionUpgradeTags', function () {
expect(graph.entity(entity.id).tags).to.eql({ shop: 'supermarket', name: 'Foo' });
});
it('upgrades a tag in a semicolon-delimited list with one other value', function () {
var oldTags = { cuisine: 'vegan' },
newTags = { 'diet:vegan': 'yes' },
entity = iD.Entity({ tags: { cuisine: 'italian;vegan', name: 'Foo' }}),
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
expect(graph.entity(entity.id).tags).to.eql({ cuisine: 'italian', 'diet:vegan': 'yes', name: 'Foo' });
});
it('upgrades a tag in a semicolon-delimited list with many other values', function () {
var oldTags = { cuisine: 'vegan' },
newTags = { 'diet:vegan': 'yes' },
entity = iD.Entity({ tags: { cuisine: 'italian;vegan;regional;american', name: 'Foo' }}),
graph = iD.actionUpgradeTags(entity.id, oldTags, newTags)(iD.coreGraph([entity]));
expect(graph.entity(entity.id).tags).to.eql({ cuisine: 'italian;regional;american', 'diet:vegan': 'yes', name: 'Foo' });
});
});