使用Google Apps脚本HTMLService进行双重HTML编码

use*_*823 3 google-apps-script

我正在使用Google Apps脚本Html服务来呈现HTML页面.

问题是HTML实体显示而不是预期的特殊字符.例如:

Miss McCleod's renders to Miss McCleod's  
view source is: "text-align: center\"> Miss McCleod's 
Run Code Online (Sandbox Code Playgroud)

渲染正常使用

<code> <?=tune.tuneName?> </code>
Run Code Online (Sandbox Code Playgroud)

但不是:

<h1 style="text-align:center;"><?=tune.tuneName?> </h1> 
Run Code Online (Sandbox Code Playgroud)

其中tune.tuneName是从Cache中提取的对象的成员变量.该对象是从谷歌电子表格中填充的,并且在放置和到达/从缓存中使用了Utilities.jsonStringify()和Utilities.jsonParse().

HTML模板脚本如下所示.

<h1 style="text-align:center;"><?=tune.tuneName?> </h1> 
<code> <?=tune.tuneName?> </code>

<div style="text-align:center;">    
  <? var imageUrl = getUrlForAttachmentFileName(tune.musicNotesImageFileName) ?>
  <img src="<?=imageUrl?>" alt="<?=tune.tuneName?>" align="center">
</div>
Run Code Online (Sandbox Code Playgroud)


以下代码用于实例化页面.

tuneRec = findTuneById(tuneId);  
var printHtmlTemplate = HtmlService.createTemplateFromFile('PrintPage');
printHtmlTemplate.tune = tuneRec;
return printHtmlTemplate.evaluate();



Miss McCleod&amp;#39;s implies that double encoding is taking place.
Run Code Online (Sandbox Code Playgroud)

如何解决上述问题的任何想法将不胜感激.

谢谢!

Cor*_*y G 6

如果您不想转义,请使用<?!=而不是<?=.