From 005927dae3a4bf18800a446cacd1cc50cf41e335 Mon Sep 17 00:00:00 2001 From: SilentSpike Date: Sun, 2 Sep 2018 13:47:47 +0100 Subject: [PATCH] Fix parsing of error type 211 --- data/core.yaml | 2 +- dist/locales/en.json | 2 +- modules/util/keepRight/errorSchema.json | 5 ++- modules/util/keepRight/keepRight_error.js | 37 ++++++++++++++++++----- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/data/core.yaml b/data/core.yaml index 164abb139..cdf3c123f 100644 --- a/data/core.yaml +++ b/data/core.yaml @@ -1067,7 +1067,7 @@ en: description: 'These errors contain self intersecting ways.' _211: title: '' - description: 'This way contains more than one node multiple times. Nodes are {var1}, {var2}. This may or may not be an error.' + description: 'This way contains more than one node multiple times. Nodes are {var1}. This may or may not be an error.' _212: title: '' description: 'This way has only two different nodes and contains one of them more than once.' diff --git a/dist/locales/en.json b/dist/locales/en.json index 4b91ec465..08e07cbd6 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -1312,7 +1312,7 @@ }, "_211": { "title": "", - "description": "This way contains more than one node multiple times. Nodes are {var1}, {var2}. This may or may not be an error." + "description": "This way contains more than one node multiple times. Nodes are {var1}. This may or may not be an error." }, "_212": { "title": "", diff --git a/modules/util/keepRight/errorSchema.json b/modules/util/keepRight/errorSchema.json index 8c4e4c1c9..b1005cf3a 100644 --- a/modules/util/keepRight/errorSchema.json +++ b/modules/util/keepRight/errorSchema.json @@ -195,9 +195,8 @@ }, "_211": { "title": "", - "description": "This way contains more than one node at least twice. Nodes are #(\\d+), ((?:#\\d+(?:, )?)+)\\. This may or may not be an error", - "IDs": ["n"], - "TODO": "Second group is arbitrary list of node IDs in form: #ID, #ID, #ID...", + "description": "This way contains more than one node at least twice\\. Nodes are ((?:#\\d+(?:, )?)+)\\. This may or may not be an error", + "IDs": ["211"], "regex": true }, "_212": { diff --git a/modules/util/keepRight/keepRight_error.js b/modules/util/keepRight/keepRight_error.js index 887a607e1..3e785cf4d 100644 --- a/modules/util/keepRight/keepRight_error.js +++ b/modules/util/keepRight/keepRight_error.js @@ -71,7 +71,21 @@ export function parseErrorDescriptions(entity) { function fillPlaceholder(d) { return '' + d + ''; } - // arbitrary list of form: #ID(layer),#ID(layer),#ID(layer)... + // arbitrary node list of form: #ID, #ID, #ID... + function parseError211(list) { + var newList = []; + var items = list.split(', '); + + items.forEach(function(item) { + // ID has # at the front + var id = fillPlaceholder('n' + item.slice(1)); + newList.push(id); + }); + + return newList.join(', '); + } + + // arbitrary way list of form: #ID(layer),#ID(layer),#ID(layer)... function parseError231(list) { var newList = []; var items = list.split(','); @@ -123,18 +137,25 @@ export function parseErrorDescriptions(entity) { // index 0 is the whole match, skip it if (!index) return; - // Clean and link IDs if present in the group + // link IDs if present in the group idType = 'IDs' in errorTemplate ? errorTemplate.IDs[index-1] : ''; if (idType) { - // some errors have more complex ID lists/variance - if (idType === '231') { - group = parseError231(group); - } else if (['n','w','r'].includes(idType)) { + switch (idType) { // simple case just needs a linking span - group = fillPlaceholder(idType + group); + case 'n': + case 'w': + case 'r': + group = fillPlaceholder(idType + group); + break; + // some errors have more complex ID lists/variance + case '211': + group = parseError211(group); + break; + case '231': + group = parseError231(group); } } else if (html_re.test(group)) { - // escape any html + // escape any html in non-IDs group = '\\' + group + '\\'; }