Ticket #29 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

Complex companion banners or HTML in the companion DIV area cause ExternalInterface.call function to fail

Reported by: paul Owned by: paul
Priority: blocker Milestone:
Component: OVA for AS3 Version:
Keywords: Companions, Javascript Cc:
Forum thread:

Description

Reported by wildtangent, Apr 06, 2010
What steps will reproduce the problem?

  1. Load a complex HTML element with both single and double quotes, or with control characters such as \n into OpenX as a companion advert.
  1. Load JWPlayer or Flowplayer with showCompanions and simple companion configuration
  1. Observe in Firebug as the ExternalInterface function fails to execute (e.g. Unterminated String Literal, or Unexpected ; )

What is the expected output? What do you see instead?
Instead of the companion div content being replaced, the method fails and no change is seen to the companion div innerHTML.

What version of the product are you using? On what operating system?
Using 0.4.5 but have checked trunk and this also has the same code in the OpenAdStreamer.as file

Please provide any additional information below.

To fix this simply, you can escape or replace the #content in the calls calls to innerHTML=

like so:

...Line 272 - onDisplayCompanionAd()
ExternalInterface.call("function(){ document.getElementById('" +
companionEvent.divID + "').innerHTML='" +
StringUtils.replaceControlChars(StringUtils.replaceSingleWithDoubleQuotes(companionEvent.content))
+ "'; }");

...Line 295 - onHideCompanionAd()
ExternalInterface.call("function(){ document.getElementById('" +
_previousDivContent[i].divId + "').innerHTML='" +
StringUtils.removeControlChars(StringUtils.replaceSingleWithDoubleQuotes)_previousDivContent[i].content))
+ "'; }");

The above method is tested and seems to work as expected, with the exception described below.

For a more readable fix, suggest wrapping both replaceSingleWithDoubleQuotes and removeControlChars in a single function inside of the StringUtils class, or escaping the whole HTML string instead of performing replacement operations on it.

CAVEAT TO THE ABOVE FUNCTIONING...
I have noticed that if trying to load a complex bit of HTML which in turn loads a script, such is standard for a display ad, the HTML is correctly inserted into the DOM but no script action takes place afterwards. More investigation is needed into this which is what I am doing this evening.

Comment 2 by wildtangent, Apr 28, 2010
Hi,

I actually cleaned this up a lot further - the above solution actually gives a null object error if there was no HTML in the DIV prior to the companion being loaded. My new version actually passes the strings directly through as variables into a JavaScript function, which is much cleaner and does not break with special characters.

I'll email you in a second with the code I wrote to handle this. Sorry it's not in diff form, I'm not a master of committing to open source projects yet ;)

Joe

Change History

comment:1 Changed 3 years ago by paul

  • Status changed from new to closed
  • Resolution set to fixed

Fixed. Closed

Note: See TracTickets for help on using tickets.