Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Replace use of startsWith and endsWith with regex for IE11 #1877

Merged
merged 1 commit into from Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/marked.esm.js
Expand Up @@ -438,11 +438,11 @@ var Tokenizer_1 = class Tokenizer {
let text = cap[2].trim();

// remove trailing #s
if (text.endsWith('#')) {
if (/#$/.test(text)) {
const trimmed = rtrim$1(text, '#');
if (this.options.pedantic) {
text = trimmed.trim();
} else if (!trimmed || trimmed.endsWith(' ')) {
} else if (!trimmed || / $/.test(trimmed)) {
// CommonMark requires space before trailing #s
text = trimmed.trim();
}
Expand Down Expand Up @@ -785,9 +785,9 @@ var Tokenizer_1 = class Tokenizer {
const cap = this.rules.inline.link.exec(src);
if (cap) {
const trimmedUrl = cap[2].trim();
if (!this.options.pedantic && trimmedUrl.startsWith('<')) {
if (!this.options.pedantic && /^</.test(trimmedUrl)) {
// commonmark requires matching angle brackets
if (!trimmedUrl.endsWith('>')) {
if (!(/>$/.test(trimmedUrl))) {
return;
}

Expand Down Expand Up @@ -822,8 +822,8 @@ var Tokenizer_1 = class Tokenizer {
}

href = href.trim();
if (href.startsWith('<')) {
if (this.options.pedantic && !trimmedUrl.endsWith('>')) {
if (/^</.test(href)) {
if (this.options.pedantic && !(/>$/.test(trimmedUrl))) {
// pedantic allows starting angle bracket without ending angle bracket
href = href.slice(1);
} else {
Expand Down Expand Up @@ -906,7 +906,7 @@ var Tokenizer_1 = class Tokenizer {
if (cap) {
let text = cap[2].replace(/\n/g, ' ');
const hasNonSpaceChars = /[^ ]/.test(text);
const hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
text = text.substring(1, text.length - 1);
}
Expand Down
14 changes: 7 additions & 7 deletions lib/marked.js
Expand Up @@ -534,12 +534,12 @@
if (cap) {
var text = cap[2].trim(); // remove trailing #s

if (text.endsWith('#')) {
if (/#$/.test(text)) {
var trimmed = rtrim$1(text, '#');

if (this.options.pedantic) {
text = trimmed.trim();
} else if (!trimmed || trimmed.endsWith(' ')) {
} else if (!trimmed || / $/.test(trimmed)) {
// CommonMark requires space before trailing #s
text = trimmed.trim();
}
Expand Down Expand Up @@ -879,9 +879,9 @@
if (cap) {
var trimmedUrl = cap[2].trim();

if (!this.options.pedantic && trimmedUrl.startsWith('<')) {
if (!this.options.pedantic && /^</.test(trimmedUrl)) {
// commonmark requires matching angle brackets
if (!trimmedUrl.endsWith('>')) {
if (!/>$/.test(trimmedUrl)) {
return;
} // ending angle bracket cannot be escaped

Expand Down Expand Up @@ -921,8 +921,8 @@

href = href.trim();

if (href.startsWith('<')) {
if (this.options.pedantic && !trimmedUrl.endsWith('>')) {
if (/^</.test(href)) {
if (this.options.pedantic && !/>$/.test(trimmedUrl)) {
// pedantic allows starting angle bracket without ending angle bracket
href = href.slice(1);
} else {
Expand Down Expand Up @@ -1017,7 +1017,7 @@
if (cap) {
var text = cap[2].replace(/\n/g, ' ');
var hasNonSpaceChars = /[^ ]/.test(text);
var hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
var hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);

if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
text = text.substring(1, text.length - 1);
Expand Down
2 changes: 1 addition & 1 deletion marked.min.js

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/Tokenizer.js
Expand Up @@ -124,11 +124,11 @@ module.exports = class Tokenizer {
let text = cap[2].trim();

// remove trailing #s
if (text.endsWith('#')) {
if (/#$/.test(text)) {
const trimmed = rtrim(text, '#');
if (this.options.pedantic) {
text = trimmed.trim();
} else if (!trimmed || trimmed.endsWith(' ')) {
} else if (!trimmed || / $/.test(trimmed)) {
// CommonMark requires space before trailing #s
text = trimmed.trim();
}
Expand Down Expand Up @@ -471,9 +471,9 @@ module.exports = class Tokenizer {
const cap = this.rules.inline.link.exec(src);
if (cap) {
const trimmedUrl = cap[2].trim();
if (!this.options.pedantic && trimmedUrl.startsWith('<')) {
if (!this.options.pedantic && /^</.test(trimmedUrl)) {
// commonmark requires matching angle brackets
if (!trimmedUrl.endsWith('>')) {
if (!(/>$/.test(trimmedUrl))) {
return;
}

Expand Down Expand Up @@ -508,8 +508,8 @@ module.exports = class Tokenizer {
}

href = href.trim();
if (href.startsWith('<')) {
if (this.options.pedantic && !trimmedUrl.endsWith('>')) {
if (/^</.test(href)) {
if (this.options.pedantic && !(/>$/.test(trimmedUrl))) {
// pedantic allows starting angle bracket without ending angle bracket
href = href.slice(1);
} else {
Expand Down Expand Up @@ -592,7 +592,7 @@ module.exports = class Tokenizer {
if (cap) {
let text = cap[2].replace(/\n/g, ' ');
const hasNonSpaceChars = /[^ ]/.test(text);
const hasSpaceCharsOnBothEnds = text.startsWith(' ') && text.endsWith(' ');
const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
text = text.substring(1, text.length - 1);
}
Expand Down