Project

General

Profile

Actions

Bug #96650

closed

typo3 11.5 spamProtectEmailAddresses Uncaught TypeError: value is undefined

Added by Thorsten Geißler almost 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
TypoScript
Target version:
-
Start date:
2022-01-26
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.4
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

If spamProtectEmailAddresses is activated, an e-mail-link wrapping some html-elements doesnt work. A click on the generated link doesnt open the e-mail client as expected. Console shows "Uncaught TypeError: value is undefined".

Example for testing in TYPOSCRIPT:


config.spamProtectEmailAddresses = 1
config.spamProtectEmailAddresses_atSubst = (at)

100 = TEXT
100.value = <span class="fa-envelope-o fa" aria-hidden="true"></span>
100.typolink.parameter = mailto:info@example.org - - "Send a mail to main TYPO3 contact" 
100.typolink.ATagBeforeWrap = 1
100.typolink.wrap = |<span>E-MAIL</span>

Greetz

Actions #1

Updated by Thorsten Geißler almost 3 years ago

  • Target version deleted (12.0)
Actions #2

Updated by Georg Ringer almost 3 years ago

  • Status changed from New to Needs Feedback

this works fine on my site. can you provide some more input, e.g. which line triggers the error? thanks a lot

Actions #3

Updated by Thorsten Geißler almost 3 years ago

Hi Georg,
for testing i put the following code on an empty site template (TYPO3 11.5.5 + PHP 7.4):

config {
spamProtectEmailAddresses = -2
}

page = PAGE
  page.100 = TEXT
  page.100.value = <span>info@example.org</span>
  page.100.typolink.parameter = mailto:info@example.org - - "Send a mail to main TYPO3 contact" 

The source-code looks like this:

<!DOCTYPE html>
<html dir="ltr" lang="de-DE">
<head>

<meta charset="utf-8">
<!-- 
    This website is powered by TYPO3 - inspiring people to share!
    TYPO3 is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.
    TYPO3 is copyright 1998-2022 of Kasper Skaarhoj. Extensions are copyright of their respective owners.
    Information and contribution at https://typo3.org/
-->

<title>Tets</title>
<meta name="generator" content="TYPO3 CMS" />
<meta name="robots" content="noindex,nofollow" />
<meta name="twitter:card" content="summary" />

<!-- This site is optimized with the Yoast SEO for TYPO3 plugin - https://yoast.com/typo3-extensions-seo/ -->
<script type="application/ld+json">[{"@context":"https:\/\/www.schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"https:\/\/www.mysite.de\/","name":"Home"}},{"@type":"ListItem","position":2,"item":{"@id":"https:\/\/www.mysite.de\/metaseiten","name":"Metaseiten"}},{"@type":"ListItem","position":3,"item":{"@id":"https:\/\/www.mysite.de\/metaseiten\/test","name":"test"}}]}]</script>
</head>
<body>
<a href="#" title="Send a mail to main TYPO3 contact" data-mailto-token="kygjrm8gldmYcvyknjc,mpe" data-mailto-vector="-2"><span>info(at)example.org</span></a>

<script async="async" src="/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195"></script>

</body>
</html>

This is the JS-file:

(function() {
  /**
   * @param {Function} callback
   */
  function ready(callback) {
    if (document.readyState === 'complete') {
      callback.call(null);
      return;
    }
    var clearListeners = function() {
      window.removeEventListener('load', delegate);
      document.removeEventListener('DOMContentLoaded', delegate);
    };
    var delegate = function() {
      clearListeners();
      callback.call(null);
    };
    window.addEventListener('load', delegate);
    document.addEventListener('DOMContentLoaded', delegate);
  }
  /**
   * Decoding helper function
   *
   * @param {number} charCode
   * @param {number} start
   * @param {number} end
   * @param {number} offset
   * @return {string}
   */
  function decryptCharcode(charCode, start, end, offset) {
    charCode = charCode + offset;
    if (offset > 0 && charCode > end) {
      charCode = start + (charCode - end - 1);
    } else if (offset < 0 && charCode < start) {
      charCode = end - (start - charCode - 1);
    }
    return String.fromCharCode(charCode);
  }
  /**
   * Decodes string
   *
   * @param {string} value
   * @param {number} offset
   * @return {string}
   */
  function decryptString(value, offset) {
    var result = '';
    for (var i=0; i < value.length; i++) {
      var charCode = value.charCodeAt(i);
      if (charCode >= 0x2B && charCode <= 0x3A) {
        result += decryptCharcode(charCode,0x2B,0x3A,offset);    /* 0-9 . , - + / : */
      } else if (charCode >= 0x40 && charCode <= 0x5A) {
        result += decryptCharcode(charCode,0x40,0x5A,offset);    /* A-Z @ */
      } else if (charCode >= 0x61 && charCode <= 0x7A) {
        result += decryptCharcode(charCode,0x61,0x7A,offset);    /* a-z */
      } else {
        result += value.charAt(i);
      }
    }
    return result;
  }

  /**
   * Opens URL in new window.
   *
   * @param {string} url
   * @param {string|null} target
   * @param {string|null} features
   * @return {Window}
   */
  function windowOpen(url, target, features) {
    var windowRef = window.open(url, target, features);
    if (windowRef) {
      windowRef.focus();
    }
    return windowRef;
  }

  // @deprecated Will be removed in TYPO3 v12.0
  if (typeof window['linkTo_UnCryptMailto'] === 'undefined') {
    window['linkTo_UnCryptMailto'] = function(value, offset) {
      console.warn('Function linkTo_UnCryptMailto() is deprecated and will be remove in TYPO3 v12.0');
      if (value && offset) {
        document.location.href = decryptString(value, offset);
      }
    };
  }

  ready(function() {
    var mailtoElements = document.querySelectorAll('a[data-mailto-token][data-mailto-vector]');
    // `Array.from` for IE compatibility
    Array.from(mailtoElements).forEach(function(element) {
        element.addEventListener('click', function(evt) {
          evt.preventDefault();
          var dataset= evt.target.dataset;
          var value = dataset.mailtoToken;
          var offset = parseInt(dataset.mailtoVector, 10) * -1;
          document.location.href = decryptString(value, offset);
        });
      });
    var openElements = document.querySelectorAll('a[data-window-url]');
    // `Array.from` for IE compatibility
    Array.from(openElements).forEach(function(element) {
        element.addEventListener('click', function(evt) {
          evt.preventDefault();
          var dataset= evt.target.dataset;
          var url = dataset.windowUrl;
          var target = dataset.windowTarget || null;
          var features = dataset.windowFeatures || null;
          windowOpen(url, target, features);
        });
      });
  });
})();

This is shown in the console, after clicking the e-mail-link:

Uncaught TypeError: value is undefined
    decryptString https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:48
    <anonymous> https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:98
    EventListener.handleEvent* https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:93
    <anonymous> https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:92
    delegate https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:16
    ready https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:18
    <anonymous> https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:89
    <anonymous> https://www.mysite.de/typo3temp/assets/js/cf202a86403c2faa6f0be9e88eef17b2.js?1643702195:114
cf202a86403c2faa6f0be9e88eef17b2.js:48:19

Thank u

Actions #4

Updated by Georg Ringer over 2 years ago

can you check latest version, can't reproduce currently

Actions #5

Updated by Thorsten Geißler over 2 years ago

Georg Ringer wrote in #note-4:

can you check latest version, can't reproduce currently

Ok. In version 11.5.14 everything works fine.

Thank U

Actions #6

Updated by Thorsten Geißler over 2 years ago

  • % Done changed from 0 to 100
Actions #7

Updated by Markus Klein about 2 years ago

  • Status changed from Needs Feedback to Closed
Actions

Also available in: Atom PDF