From 93df5d42d9039437580800e70309aaec31dbc187 Mon Sep 17 00:00:00 2001 From: Quincy Morgan Date: Mon, 11 Mar 2019 10:22:28 -0400 Subject: [PATCH] Flag and upgrade deprecated tags in a semicolon-delimited tag value (close #6038) --- modules/actions/upgrade_tags.js | 11 ++++++++++- modules/osm/entity.js | 7 ++++++- test/spec/actions/upgrade_tags.js | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/modules/actions/upgrade_tags.js b/modules/actions/upgrade_tags.js index 38ca76675..b070cc467 100644 --- a/modules/actions/upgrade_tags.js +++ b/modules/actions/upgrade_tags.js @@ -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) { diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 517540af5..3ebdf1099 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -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); diff --git a/test/spec/actions/upgrade_tags.js b/test/spec/actions/upgrade_tags.js index eba80416d..2a0e2f412 100644 --- a/test/spec/actions/upgrade_tags.js +++ b/test/spec/actions/upgrade_tags.js @@ -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' }); + }); + });