Skip to content

Commit

Permalink
Calendly: Removed look behinds in regexes (#14375)
Browse files Browse the repository at this point in the history
* Removed look behinds in regexes

This isn't supported by Firefox, IE and possibly other browsers

* Fixed the regex for the failing bare URLs test

The new regex wasn't taking into account the case where the embed code
could be a bare URL starting with `calendly.com`
  • Loading branch information
pablinos authored Jan 17, 2020
1 parent 70b7b0d commit 03212a4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions extensions/blocks/calendly/utils.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
export const getURLFromEmbedCode = embedCode => {
const url = embedCode.match( /(?<!\.)calendly\.com.+?([^"']*)/i );
const url = embedCode.match( /(^|\/\/)(calendly\.com[^"']*)/i );
if ( url ) {
return 'https://' + url[ 0 ];
return 'https://' + url[ 2 ];
}
};

export const getSubmitButtonTextFromEmbedCode = embedCode => {
let submitButtonText = embedCode.match( /(?<=false;"\>).+(?=<\/)/ );
let submitButtonText = embedCode.match( /false;"\>([^<]+)\<\// );
if ( submitButtonText ) {
return submitButtonText[ 0 ];
return submitButtonText[ 1 ];
}

submitButtonText = embedCode.match( /(?<=text: ').*?(?=')/ );
submitButtonText = embedCode.match( /text: '([^']*?)'/ );
if ( submitButtonText ) {
return submitButtonText[ 0 ];
return submitButtonText[ 1 ];
}
};

const getSubmitButtonTextColorFromEmbedCode = embedCode => {
const submitButtonTextColor = embedCode.match( /(?<= textColor: ').*?(?=')/ );
const submitButtonTextColor = embedCode.match( /textColor: '([^']*?)'/ );
if ( submitButtonTextColor ) {
return submitButtonTextColor[ 0 ];
return submitButtonTextColor[ 1 ];
}
};

const getSubmitButtonBackgroundColorFromEmbedCode = embedCode => {
const submitButtonBackgroundColor = embedCode.match( /(?<= color: ').*?(?=')/ );
const submitButtonBackgroundColor = embedCode.match( /color: '([^']*?)'/ );
if ( submitButtonBackgroundColor ) {
return submitButtonBackgroundColor[ 0 ];
return submitButtonBackgroundColor[ 1 ];
}
};

Expand Down

0 comments on commit 03212a4

Please sign in to comment.