apps-script-samples icon indicating copy to clipboard operation
apps-script-samples copied to clipboard

isAlnum function is incorrect in mailmerge example: check only latin symbols

Open Hubbitus opened this issue 4 years ago • 0 comments

Expected Behavior

Provided sample mail_merge works as described. Really it works only for headers with latin symbols (e.g. English).

Sample URL: https://sites.google.com/site/scriptsexamples/custom-methods/create-text-from-template#TOC-Documentation Description: The cause is isAlnum function. That is naively implemented as:

function isAlnum(char) {
  return char >= 'A' && char <= 'Z' ||
    char >= 'a' && char <= 'z' ||
    isDigit(char);
}

But Unicode standard describe much more "Alpha" symbols in different categories.

So really that function should be implemented like:

function isAlnum(char) {
  return !! char.match(/[\p{Number}\p{Letter}]/u)
}

and also function isDigit may be dropped (that also potentially has similar problems)

Actual Behavior

Headers on said in Russian or Korean language just ignored and values does not substituted in template.

Steps to Reproduce the Problem

  1. Run example with column name, said in Russian or Korean language.

Hubbitus avatar Feb 05 '21 23:02 Hubbitus