Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double HTML Encoding with Google Apps Script HTMLService

I am using the Google Apps Script Html Service to render an HTML page.

The problem is that the HTML Entity gets displayed and not the intended special character. For example:

Miss McCleod's renders to Miss McCleod's  
view source is: "text-align: center\"> Miss McCleod's 

Rendering works correctly with

<code> <?=tune.tuneName?> </code>

but not with:

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

where tune.tuneName is a member variable of an object that has been pulled from the Cache. The object was populated from a google spreadsheet and Utilities.jsonStringify() and Utilities.jsonParse() were used when putting and getting to/from cache.

The HTML templates script is shown below.

<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>


The following code is used to instantiate the page.

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.

Any ideas on how to solve for the above would be greatly appreciated.

Thanks!

like image 991
user1797823 Avatar asked Jan 27 '26 09:01

user1797823


1 Answers

Use <?!= instead of <?= if you don't want escaping.

like image 170
Corey G Avatar answered Jan 30 '26 10:01

Corey G



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!