From ffee3b225fc3cf2a1c09b9763d172b28d857b316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20M=C3=A9tais?= Date: Mon, 4 May 2015 16:16:33 +0200 Subject: [PATCH] Better parsing of cssParsingErrors' offenders --- lib/metadata/policies.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/metadata/policies.js b/lib/metadata/policies.js index 461f17f..c26276f 100644 --- a/lib/metadata/policies.js +++ b/lib/metadata/policies.js @@ -392,18 +392,31 @@ var policies = { list: offenders.map(function(offender) { var parts = /^(?:(?:<([^ \(]*)>|\[inline CSS\]) ?)?(?:\((((?! @ ).)*)(?: @ (\d+):(\d+))?\))?$/.exec(offender); - if (!parts) { - debug('cssParsingErrors offenders transform function error with "%s"', offender); + if (parts) { return { - parseError: offender + error: parts[2], + file: parts[1] || null, + line: (parts[4] && parts[5]) ? parseInt(parts[4], 10) : null, + column: (parts[4] && parts[5]) ? parseInt(parts[5], 10) : null }; } + // Try another syntax + parts = /^(.*) <(.*)> @ (\d+):(\d+)$/.exec(offender); + + if (parts) { + return { + error: parts[1], + file: parts[2] || null, + line: parseInt(parts[3], 10), + column: parseInt(parts[4], 10) + } + } + + + debug('cssParsingErrors offenders transform function error with "%s"', offender); return { - error: parts[2], - file: parts[1] || null, - line: (parts[4] && parts[5]) ? parseInt(parts[4], 10) : null, - column: (parts[4] && parts[5]) ? parseInt(parts[5], 10) : null + parseError: offender }; }) };