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] ensure the email address part is the only value captured when a… #1191

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ var add_contact_from_popup = function(event) {


if (contact) {
var emailRegex = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g;
var email = contact.match(emailRegex)[0];
var name = contact.replace(emailRegex, "");
var email = contact.match(EMAIL_REGEX)[0];
var name = contact.replace(EMAIL_REGEX, "");

var saveContactContent = `<div><table>
<tr><td><strong>${hm_trans('Name')} :</strong></td><td>${name}</td></tr>
Expand Down
10 changes: 9 additions & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
'use strict';

// Constants. To be used anywhere in the app via the window object.
const globalVars = {
EMAIL_REGEX: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
}
Object.keys(globalVars).forEach(key => {
window[key] = globalVars[key];
});

/* extend cash.js with some useful bits */
$.inArray = function(item, list) {
for (var i in list) {
Expand Down Expand Up @@ -2644,7 +2652,7 @@ const handleExternalResources = (inline) => {
const messageContainer = document.querySelector('.msg_text_inner');
messageContainer.insertAdjacentHTML('afterbegin', '<div class="external_notices"></div>');

const sender = document.querySelector('#contact_info').textContent.trim().replace(/\s/g, '_') + 'external_resources_allowed';
const sender = document.querySelector('#contact_info').textContent.match(EMAIL_REGEX)[0] + '_external_resources_allowed';
const elements = messageContainer.querySelectorAll('[data-src]');
const blockedResources = [];
elements.forEach(function (element) {
Expand Down