diff --git a/lib/marked.js b/lib/marked.js
index 5ca95941ec..a6a2bbe6a5 100644
--- a/lib/marked.js
+++ b/lib/marked.js
@@ -55,7 +55,7 @@ block._tag = '(?!(?:'
block.html = edit(block.html)
.replace('comment', //)
.replace('closed', /<(tag)[\s\S]+?<\/\1>/)
- .replace('closing', /]*)*?\/?>/)
+ .replace('closing', /\s]*)*?\/?>/)
.replace(/tag/g, block._tag)
.getRegex();
@@ -461,10 +461,10 @@ var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
url: noop,
- tag: /^|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/]*)*?\/?>/,
+ tag: /^|^<\/?[a-zA-Z0-9\-]+(?:"[^"]*"|'[^']*'|\s[^<'">\/\s]*)*?\/?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
- nolink: /^!?\[((?:\[[^\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
+ nolink: /^!?\[((?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^_([^\s_](?:[^_]|__)+?[^\s_])_\b|^\*((?:\*\*|[^*])+?)\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`]?)\s*\1(?!`)/,
@@ -481,7 +481,7 @@ inline.autolink = edit(inline.autolink)
.replace('email', inline._email)
.getRegex()
-inline._inside = /(?:\[[^\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
+inline._inside = /(?:\[[^\[\]]*\]|\\[\[\]]|[^\[\]]|\](?=[^\[]*\]))*/;
inline._href = /\s*([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
inline.link = edit(inline.link)
diff --git a/test/new/headings-id.html b/test/new/headings_id.html
similarity index 100%
rename from test/new/headings-id.html
rename to test/new/headings_id.html
diff --git a/test/new/headings-id.md b/test/new/headings_id.md
similarity index 100%
rename from test/new/headings-id.md
rename to test/new/headings_id.md
diff --git a/test/new/redos_html_closing.html b/test/new/redos_html_closing.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/new/redos_html_closing.md b/test/new/redos_html_closing.md
new file mode 100644
index 0000000000..65bc5f7362
--- /dev/null
+++ b/test/new/redos_html_closing.md
@@ -0,0 +1 @@
+a'a
diff --git a/test/new/redos_nolink.html b/test/new/redos_nolink.html
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/test/new/redos_nolink.md b/test/new/redos_nolink.md
new file mode 100644
index 0000000000..a43a156820
--- /dev/null
+++ b/test/new/redos_nolink.md
@@ -0,0 +1 @@
+![\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]\[[]!\