Correctly escape chars in email addresses

Without this, some email address with strange chars were not removable
master
Daniel Berteaud 11 years ago
parent bd0535c940
commit 652682b00a
  1. 11
      public/js/vroom.js

@ -81,8 +81,8 @@ function inviteUrlPopup(){
// Add a new email address to be notified whn someone joins // Add a new email address to be notified whn someone joins
function addNotifiedEmail(email){ function addNotifiedEmail(email){
var id = email.replace('@', '_AT_').replace('.', '_DOT_'); var id = email.replace(/['"]/g, '_');
$('<li></li>').html(email + ' <a href="javascript:void(0);" onclick="removeNotifiedEmail(\'' + email + '\');" title="' + locale.REMOVE_THIS_ADDRESS + '">' + $('<li></li>').html(email + ' <a href="javascript:void(0);" onclick="removeNotifiedEmail(\'' + email.replace('\'', '\\\'') + '\');" title="' + locale.REMOVE_THIS_ADDRESS + '">' +
' <span class="glyphicon glyphicon-remove-circle"></span>' + ' <span class="glyphicon glyphicon-remove-circle"></span>' +
' </a>') ' </a>')
.attr('id', 'emailNotification_' + id) .attr('id', 'emailNotification_' + id)
@ -91,7 +91,7 @@ function addNotifiedEmail(email){
// Remove the address from the list // Remove the address from the list
function removeNotifiedEmail(email){ function removeNotifiedEmail(email){
var id = email.replace('@', '_AT_').replace('.', '_DOT_'); var id = escapeJqSelector(email.replace(/['"]/, '_').replace('\\\'', '\''));
$.ajax({ $.ajax({
data: { data: {
action: 'emailNotification', action: 'emailNotification',
@ -115,6 +115,11 @@ function removeNotifiedEmail(email){
}); });
} }
// Taken from http://totaldev.com/content/escaping-characters-get-valid-jquery-id
function escapeJqSelector(string){
return string.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1');
}
// Escape entities // Escape entities
function stringEscape(string){ function stringEscape(string){
string = string.replace(/[\u00A0-\u99999<>\&]/gim, function(i) { string = string.replace(/[\u00A0-\u99999<>\&]/gim, function(i) {

Loading…
Cancel
Save