apps-script-samples
apps-script-samples copied to clipboard
isAlnum function is incorrect in mailmerge example: check only latin symbols
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
- Run example with column name, said in Russian or Korean language.