Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Ensured that our code is always injected before user's code to avoid …
Browse files Browse the repository at this point in the history
…breaking gadgets that have code in the head of the document that depends on injected javascript.

git-svn-id: https://svn.apache.org/repos/asf/incubator/shindig/trunk@702968 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Kevin Brown committed Oct 8, 2008
1 parent 279f6ae commit 1387354
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ private GadgetContent createGadgetContent(Gadget gadget, MutableContent mutableC
if (matcher.matches()) {
GadgetContent content = new GadgetContent();
content.appendHead(matcher.group(BEFORE_HEAD_GROUP))
.appendHead("<head>")
.appendHead(matcher.group(HEAD_GROUP));
.appendHead("<head>");

content.appendBody("</head>")
content.appendBody(matcher.group(HEAD_GROUP))
.appendBody("</head>")
.appendBody(createBodyTag(gadget, matcher.group(BODY_ATTRIBUTES_GROUP)))
.appendBody(matcher.group(BODY_GROUP));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,28 @@ public String getParameter(String name) {
assertTrue("Requested scripts not inlined.", rewritten.contains("foo_content();"));
}

@Test
public void featuresInjectedBeforeExistingScript() throws Exception {
Gadget gadget = makeDefaultGadget();
control.replay();

String rewritten = rewrite(gadget,
"<html><head><script src='foo.js'></script></head><body>hello</body></html>");

Matcher matcher = DOCUMENT_SPLIT_PATTERN.matcher(rewritten);
assertTrue("Output is not valid HTML.", matcher.matches());

String headContent = matcher.group(HEAD_GROUP);

// Locate user script.
int userPosition = headContent.indexOf("<script src='foo.js'></script>");

// Anything else here, we added.
int ourPosition = headContent.indexOf("<script>");

assertTrue("Injected script must come before user script.", ourPosition < userPosition);
}

@Test
public void urlFeaturesForcedExternal() throws Exception {
String gadgetXml =
Expand Down

0 comments on commit 1387354

Please sign in to comment.