Fix parsing of error type 231

This commit is contained in:
SilentSpike
2018-09-02 11:05:37 +01:00
committed by Bryan Housel
parent a2fe431637
commit e0e48b7505
3 changed files with 34 additions and 7 deletions
+1 -1
View File
@@ -1082,7 +1082,7 @@ en:
description: ''
_231:
title: 'mixed layers intersection'
description: 'This node is a junction of ways on different layers: {var1}({var2}), {var3}.'
description: 'This node is a junction of ways on different layers: {var1}.'
_232:
title: 'strange layers'
description: 'This {var1} is tagged with layer {var2}. This need not be an error but it looks strange.'
+2 -3
View File
@@ -193,9 +193,8 @@
},
"_231": {
"title": "mixed layers intersection",
"description": "This node is a junction of ways on different layers: #(\\d+)\\((-?\\d+)\\),((?:#\\d+\\(-?\\d+\\),?)+)",
"IDs": ["w", ""],
"TODO": "Third group is arbitrary list of way IDs and their layer value in form: #ID(layer),#ID(layer),#ID(layer)..."
"description": "This node is a junction of ways on different layers: ((?:#\\d+\\(-?\\d+\\),?)+)",
"IDs": ["231"]
},
"_232": {
"title": "strange layers",
+31 -3
View File
@@ -70,6 +70,31 @@ export function parseErrorDescriptions(entity) {
function fillPlaceholder(d) { return '<span><a class="kr_error_description-id">' + d + '</a></span>'; }
// arbitrary list of way IDs and their layer value in form: #ID(layer),#ID(layer),#ID(layer)...
function parseError231(list) {
var newList = [];
var items = list.split(',');
items.forEach(function(item) {
var id;
var layer;
// item of form "#ID(layer)"
item = item.split('(');
// ID has # at the front
id = item[0].slice(1);
id = fillPlaceholder('w' + id);
// layer has trailing )
layer = item[1].slice(0,-1);
newList.push(id + ' (layer: ' + layer + ')');
});
return newList.join(', ');
}
// regex pattern should capture groups to extract appropriate details
var errorDescription = entity.description;
var errorRe = new RegExp(matchingTemplate.description);
@@ -89,12 +114,15 @@ export function parseErrorDescriptions(entity) {
for (var i = 1; i < errorMatch.length; i++) {
var group = errorMatch[i];
// IDs captured have an associated type
// Clean and link IDs if present in the error
if ('IDs' in matchingTemplate && matchingTemplate.IDs[i-1]) {
var prefix = matchingTemplate.IDs[i-1];
// wrap id with linking span if valid
if (['n','w','r'].includes(prefix)) {
// some errors have more complex ID lists/variance
if (prefix === '231') {
group = parseError231(group);
} else if (['n','w','r'].includes(prefix)) {
// wrap with linking span if simple case
group = fillPlaceholder(prefix + group);
}
} else if (html_re.test(group)) {