Improved Soundcloud regex, added escaping

This commit is contained in:
Igor Zhukov 2014-11-14 13:32:21 +03:00
parent 1f159bc8c9
commit cab5631cb9
2 changed files with 7 additions and 5 deletions

View File

@ -214,8 +214,8 @@ angular.module('myApp.directives', ['myApp.filters'])
case 'soundcloud': case 'soundcloud':
var soundcloudUrl = embedData[1]; var soundcloudUrl = embedData[1];
html = '<div class="im_message_media_embed im_message_soundcloud_embed"><' + embedTag + ' type="text/html" frameborder="0" ' + html = '<div class="im_message_media_embed im_message_soundcloud_embed"><' + embedTag + ' type="text/html" frameborder="0" ' +
'src="https://w.soundcloud.com/player/?url=' + soundcloudUrl + 'src="https://w.soundcloud.com/player/?url=' + encodeEntities(encodeURIComponent(soundcloudUrl)) +
'&auto_play=false&hide_related=true&show_comments=false&show_user=true&show_reposts=false&visual=true"></' + embedTag + '></div>'; '&amp;auto_play=false&amp;hide_related=true&amp;show_comments=false&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></' + embedTag + '></div>';
break; break;
case 'twitter': case 'twitter':

View File

@ -3114,14 +3114,14 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars;
var regExp = new RegExp('((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>"\']))|(\\n)|(' + emojiUtf.join('|') + ')|(^|\\s)(#[' + regexAlphaNumericChars + ']{3,20})', 'i'); var regExp = new RegExp('((?:(ftp|https?)://|(?:mailto:)?([A-Za-z0-9._%+-]+@))(\\S*\\.\\S*[^\\s.;,(){}<>"\']))|(\\n)|(' + emojiUtf.join('|') + ')|(^|\\s)(#[' + regexAlphaNumericChars + ']{3,20})', 'i');
var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|.be|be.com|.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/; var youtubeRegex = /(?:https?:\/\/)?(?:www\.)?youtu(?:|\.be|be\.com|\.b)(?:\/v\/|\/watch\\?v=|e\/|(?:\/\??#)?\/watch(?:.+)v=)(.{11})(?:\&[^\s]*)?/;
var vimeoRegex = /(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)/; var vimeoRegex = /(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)/;
var instagramRegex = /https?:\/\/(?:instagr\.am\/p\/|instagram\.com\/p\/)([a-zA-Z0-9\-\_]+)/i; var instagramRegex = /https?:\/\/(?:instagr\.am\/p\/|instagram\.com\/p\/)([a-zA-Z0-9\-\_]+)/i;
var vineRegex = /https?:\/\/vine\.co\/v\/([a-zA-Z0-9\-\_]+)/i; var vineRegex = /https?:\/\/vine\.co\/v\/([a-zA-Z0-9\-\_]+)/i;
var twitterRegex = /https?:\/\/twitter\.com\/.+?\/status\/\d+/i; var twitterRegex = /https?:\/\/twitter\.com\/.+?\/status\/\d+/i;
var facebookRegex = /https?:\/\/(?:www\.)?facebook\.com\/.+?\/posts\/\d+/i; var facebookRegex = /https?:\/\/(?:www\.)?facebook\.com\/.+?\/posts\/\d+/i;
var gplusRegex = /https?:\/\/plus\.google\.com\/\d+\/posts\/[a-zA-Z0-9\-\_]+/i; var gplusRegex = /https?:\/\/plus\.google\.com\/\d+\/posts\/[a-zA-Z0-9\-\_]+/i;
var soundcloudRegex = /https?:\/\/(soundcloud.com|snd.sc)\/[a-zA-Z0-9\-\_]+\/[a-zA-Z0-9\-\_]+/i; var soundcloudRegex = /https?:\/\/(?:soundcloud\.com|snd\.sc)\/([a-zA-Z0-9%\-\_]+)\/([a-zA-Z0-9%\-\_]+)/i;
return { return {
wrapRichText: wrapRichText, wrapRichText: wrapRichText,
@ -3268,8 +3268,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return ['vine', embedUrlMatches[1]]; return ['vine', embedUrlMatches[1]];
} }
else if (embedUrlMatches = text.match(soundcloudRegex)) { else if (embedUrlMatches = text.match(soundcloudRegex)) {
if (embedUrlMatches[1] != 'explore') {
return ['soundcloud', embedUrlMatches[0]]; return ['soundcloud', embedUrlMatches[0]];
} }
}
if (!Config.Modes.chrome_packed) { // Need external JS if (!Config.Modes.chrome_packed) { // Need external JS
if (embedUrlMatches = text.match(twitterRegex)) { if (embedUrlMatches = text.match(twitterRegex)) {