Skip to content

Commit

Permalink
Merge pull request #1166 from jacob-js/fix-external-res
Browse files Browse the repository at this point in the history
[FIX] ensure the email address part is the only value captured when allowing the display of external resources from a particular sender
  • Loading branch information
Shadow243 authored Aug 20, 2024
2 parents e70db0e + 0977e5d commit 22da66e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit 22da66e

Please sign in to comment.