From 75452ba11b3b1c6074b99f54b7a7a592e2adb0f1 Mon Sep 17 00:00:00 2001 From: Golmote Date: Fri, 12 Jun 2015 21:35:06 +0200 Subject: [PATCH] Markup: optimized tag's regexp so that it stops crashing on large unclosed tags --- components/prism-markup.js | 2 +- components/prism-markup.min.js | 2 +- prism.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/prism-markup.js b/components/prism-markup.js index febdc98171..eeec921065 100644 --- a/components/prism-markup.js +++ b/components/prism-markup.js @@ -4,7 +4,7 @@ Prism.languages.markup = { 'doctype': //, 'cdata': //i, 'tag': { - pattern: /<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, + pattern: /<\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i, inside: { 'tag': { pattern: /^<\/?[^\s>\/]+/i, diff --git a/components/prism-markup.min.js b/components/prism-markup.min.js index dece1fb7eb..458e87ec48 100644 --- a/components/prism-markup.min.js +++ b/components/prism-markup.min.js @@ -1 +1 @@ -Prism.languages.markup={comment://,prolog:/<\?.+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/=|>|"/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(t){"entity"===t.type&&(t.attributes.title=t.content.replace(/&/,"&"))}); \ No newline at end of file +Prism.languages.markup={comment://,prolog:/<\?.+?\?>/,doctype://,cdata://i,tag:{pattern:/<\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,inside:{tag:{pattern:/^<\/?[^\s>\/]+/i,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"attr-value":{pattern:/=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,inside:{punctuation:/=|>|"/}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:/&#?[\da-z]{1,8};/i},Prism.hooks.add("wrap",function(t){"entity"===t.type&&(t.attributes.title=t.content.replace(/&/,"&"))}); \ No newline at end of file diff --git a/prism.js b/prism.js index ace59c0437..cdf4543ed8 100644 --- a/prism.js +++ b/prism.js @@ -441,7 +441,7 @@ Prism.languages.markup = { 'doctype': //, 'cdata': //i, 'tag': { - pattern: /<\/?[^\s>\/]+\s*(?:\s+[^\s>\/=]+(?:=(?:("|')(\\?[\w\W])*?\1|[^\s'">=]+))?\s*)*\/?>/i, + pattern: /<\/?[^\s>\/]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i, inside: { 'tag': { pattern: /^<\/?[^\s>\/]+/i,