krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 157 forks source link

«&» are escaped as «&» resulting in bad calls #206

Closed dugwood closed 8 years ago

dugwood commented 8 years ago

I was trying to asynchronously load SmartAdServer requests, but the urls are rewritten: https://jsfiddle.net/x1m6mvv6/5/

Request URL:https://ww62.smartadserver.com/ac?nwid=0&siteid=2301&pgid=378531&fmtid=438&visit=m&tmstp=5021521458&orgfmtid=438&tag=sas_438&pgDomain=https://fiddle.jshell.net

=> should not have «&»

I know that SmartAdServer provides an asynchronous mode, but I have some passbacks that won't work after the main call.

Maybe related to: https://github.com/krux/postscribe/issues/98

Thanks.

sethyates commented 8 years ago

Hi @dugwood,

I've looked into this more. The escaping actually appears to be coming from SAS themselves. I modified your fiddle as follows:

  1. replaced the postscribe call with an inline call sas.call("std", { siteId: 2301, pageId: 378531, formatId: 438, target: ''});
  2. clicked on https://ww62.smartadserver.com/config.js?nwid=62 which redirected to https://ww62.smartadserver.com/diff/js/smart.js.
  3. copies the contents of that file
  4. pasted the contents of that file at the top of the JavaScript pane
  5. removed the external resources
  6. added the following code at the top of the JavaScript pane: document.write = console.debug;
  7. clicked Run and checked the Developer Tools console and observed:
<script id="sas_script1" type="text/javascript" src="https://ww62.smartadserver.com/ac?nwid=0&amp;siteid=2301&amp;pgid=378531&am…43&amp;orgfmtid=438&amp;tag=sas_438&amp;pgDomain=https://fiddle.jshell.net"></script>
dugwood commented 8 years ago

I think I won't have to use it anymore, but so far this document.write seems good to me: & should be escaped as & in url that are part of an attribute. But if there's a call (img.src or ajax call), those & should be dealt as &.

Thanks for your time and great script anyway.