From 937c91c671b825889fdd0fdbfd5b10695673a57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E6=B4=A5?= Date: Thu, 2 Nov 2017 17:25:18 +0800 Subject: [PATCH 1/5] bug fix angular pattern escaped character conversion problem --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8465da00..b1498249 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ module.exports = function(content) { content = [content]; links.forEach(function(link) { if(!loaderUtils.isUrlRequest(link.value, root)) return; - + if (link.value.indexOf('mailto:') > -1 ) return; var uri = url.parse(link.value); @@ -129,6 +129,9 @@ module.exports = function(content) { } if(config.interpolate && config.interpolate !== 'require') { + content = content.replace(/(ng-)?pattern="\/([^"]+)\/"/g, function (pattern, $1, $2) { + return `ng-pattern="/${$2.replace(/\\([dw])/g, '\\\\$1')}/"`; + }); content = compile('`' + content + '`').code; } else { content = JSON.stringify(content); From 3b8c206d005d0c844cd2a7d78bd7f136c6894bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E6=B4=A5?= Date: Thu, 2 Nov 2017 18:49:41 +0800 Subject: [PATCH 2/5] make regexp right --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b1498249..4b72f0b1 100644 --- a/index.js +++ b/index.js @@ -129,7 +129,7 @@ module.exports = function(content) { } if(config.interpolate && config.interpolate !== 'require') { - content = content.replace(/(ng-)?pattern="\/([^"]+)\/"/g, function (pattern, $1, $2) { + content = content.replace(/(ng-)?pattern=(["']?\/((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)\/["']?)/g, function (pattern, $1, $2) { return `ng-pattern="/${$2.replace(/\\([dw])/g, '\\\\$1')}/"`; }); content = compile('`' + content + '`').code; From 58f331803c3842f9ab1ca2910211ef531ace5cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E6=B4=A5?= Date: Thu, 2 Nov 2017 19:08:01 +0800 Subject: [PATCH 3/5] make regexp right --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 4b72f0b1..91e90043 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,7 @@ module.exports = function(content) { if(config.interpolate && config.interpolate !== 'require') { content = content.replace(/(ng-)?pattern=(["']?\/((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)\/["']?)/g, function (pattern, $1, $2) { - return `ng-pattern="/${$2.replace(/\\([dw])/g, '\\\\$1')}/"`; + return `ng-pattern=${$2.replace(/\\([dw])/g, '\\\\$1')}`; }); content = compile('`' + content + '`').code; } else { From 65da04bf555884933c1158dc1505ad86e404a894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E6=B4=A5?= Date: Thu, 2 Nov 2017 19:22:22 +0800 Subject: [PATCH 4/5] make regexp right --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 91e90043..668ccbcb 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,7 @@ module.exports = function(content) { if(config.interpolate && config.interpolate !== 'require') { content = content.replace(/(ng-)?pattern=(["']?\/((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)\/["']?)/g, function (pattern, $1, $2) { - return `ng-pattern=${$2.replace(/\\([dw])/g, '\\\\$1')}`; + return `ng-pattern=${$2.replace(/\\(.)/g, '\\\\$1')}`; }); content = compile('`' + content + '`').code; } else { From 39865034041f29b0a2fbcd5844a3c25d39c12d01 Mon Sep 17 00:00:00 2001 From: jinker Date: Fri, 3 Nov 2017 09:09:51 +0800 Subject: [PATCH 5/5] make regexp support ng-* pattern --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 668ccbcb..6ed04236 100644 --- a/index.js +++ b/index.js @@ -129,8 +129,8 @@ module.exports = function(content) { } if(config.interpolate && config.interpolate !== 'require') { - content = content.replace(/(ng-)?pattern=(["']?\/((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)\/["']?)/g, function (pattern, $1, $2) { - return `ng-pattern=${$2.replace(/\\(.)/g, '\\\\$1')}`; + content = content.replace(/(?:(?:ng-)?pattern|ng-[^=]+)=(["']?\/((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)\/["']?)/g, function (pattern, $1, $2) { + return `${$1}=${$2.replace(/\\(.)/g, '\\\\$1')}`; }); content = compile('`' + content + '`').code; } else {