vendor/assets/javascripts/prism-plugin/prism-autolinker.js in prism-rails-1.6.0.3 vs vendor/assets/javascripts/prism-plugin/prism-autolinker.js in prism-rails-1.19.0

- old
+ new

@@ -5,25 +5,25 @@ typeof global !== 'undefined' && !global.Prism ) { return; } -var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:#=?&]+/, +var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:=&@]+(?:\?[\w\-+%~/.:=?&!$'()*,;@]*)?(?:#[\w\-+%~/.:#=?&!$'()*,;@]*)?/, email = /\b\S+@[\w.]+[a-z]{2}/, linkMd = /\[([^\]]+)]\(([^)]+)\)/, - + // Tokens that may contain URLs and emails candidates = ['comment', 'url', 'attr-value', 'string']; Prism.plugins.autolinker = { processGrammar: function (grammar) { // Abort if grammar has already been processed if (!grammar || grammar['url-link']) { return; } Prism.languages.DFS(grammar, function (key, def, type) { - if (candidates.indexOf(type) > -1 && Prism.util.type(def) !== 'Array') { + if (candidates.indexOf(type) > -1 && !Array.isArray(def)) { if (!def.pattern) { def = this[key] = { pattern: def }; } @@ -53,24 +53,29 @@ }); Prism.hooks.add('wrap', function(env) { if (/-link$/.test(env.type)) { env.tag = 'a'; - + var href = env.content; - + if (env.type == 'email-link' && href.indexOf('mailto:') != 0) { href = 'mailto:' + href; } else if (env.type == 'md-link') { // Markdown var match = env.content.match(linkMd); - + href = match[2]; env.content = match[1]; } - + env.attributes.href = href; + + // Silently catch any error thrown by decodeURIComponent (#1186) + try { + env.content = decodeURIComponent(env.content); + } catch(e) {} } }); -})(); \ No newline at end of file +})();