Parsing Javascript in page Header

64 views
Skip to first unread message

Jared Rodriguez

unread,
Nov 25, 2014, 3:12:31 PM11/25/14
to google-s...@googlegroups.com
Hi Dhanji,

I am using SiteBricks all over the place and it runs great.  We have a new project that we are working on and it uses EXTJS 5.  One of the things that EXT does is put a big chunk of script into the header of an index page and I have a brick that fronts that index page.  As the sitebricks parses the index.html page, it seems to be incorrectly parsing the contents of that script block.  The script block has a segment of 

for(f=0;f<l;f++)

which the parser sees as an open tag, even though this is inside of a script block.  Thus it tries to correct the html and puts all these close tags before the close of </script>  Which plays havok when the page tries to render in the browser.

The only thing that I really do in the brick is have some logic in a routine annotated with @Get that determines if I need to redirect somewhere else and if not it returns null.  In this case, all is good, so the method returns null and thus sitebricks tries to return the index page.

Have you seen this before, where a script take in the page header has a for loop that causes the parsing to hose up?

Jared Rodriguez

unread,
Nov 25, 2014, 3:23:52 PM11/25/14
to google-s...@googlegroups.com
Is JSoup what is used to parse the html page that will be returned from the brick?  I can dig in on the JSoup side if that is where the error is occurring.

Dhanji R. Prasanna

unread,
Nov 25, 2014, 3:42:36 PM11/25/14
to google-s...@googlegroups.com
Hmm. It wont parse inside script unless you have something that resembles an @XXX

But that's weird. As a simple fix you can just wrap your script in a <[CDATA tag:

--
You received this message because you are subscribed to the Google Groups "Google Sitebricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebri...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jared Rodriguez

unread,
Nov 26, 2014, 5:38:59 AM11/26/14
to
Thanks.  That might work.  I am tracking this down now.  I see in HtmlParser line 200 that it is reaching the script tag, but when asking JSoup if tag.isData(), it returns false, which is causing the HTML parser to parse the content.  I find it hard to believe that this is a JSoup bug and not something odd about my environment.  I should have it tracked down soon.  I will keep you posted on this forum as just an FYI to help others that might encounter the same thing.

Jared Rodriguez

unread,
Nov 26, 2014, 6:04:18 AM11/26/14
to google-s...@googlegroups.com
Looks like it is a bug in JSoup.  org.jsoup.parser.Tag

The script tag returns false for isData().  The comments show that it should be treated like a data node (line 245) yet the logic for isData() on the script tag always returns false.  I will let them know.


On Wednesday, November 26, 2014 5:38:59 AM UTC-5, Jared Rodriguez wrote:
Thanks.  That might work.  I am tracking this down now.  I see in HtmlParser line 200 that it is reaching the script tag, but when asking JSoup if tag.isData(), it returns false, which is causing the HTML parser to parse the content.  I find it hard to believe that this is a JSoup bug and not something odd about my environment.  I should have it tracked down soon.  I will keep you posted on this forum as just an FYI to help others that might encounter the same thing.

On Tuesday, November 25, 2014 3:42:36 PM UTC-5, dhanji wrote:

Dhanji R. Prasanna

unread,
Nov 26, 2014, 11:36:43 AM11/26/14
to google-s...@googlegroups.com
Damn ok. Maybe we need to update our version of jsoup as well. We can also be defensive about this by checking the tag name.
Let me do those two things today

Dhanji R. Prasanna

unread,
Dec 1, 2014, 2:35:35 PM12/1/14
to google-s...@googlegroups.com
Jared, were you able to get around this by using CDATA tags?

To unsubscribe from this group and stop receiving emails from it, send an email to google-sitebricks+unsubscribe@googlegroups.com.

Dhanji R. Prasanna

unread,
Dec 2, 2014, 1:25:39 PM12/2/14
to google-s...@googlegroups.com
I've made these changes--they are in master. Will do a new release next week

Jared Rodriguez

unread,
Dec 3, 2014, 5:45:06 AM12/3/14
to google-s...@googlegroups.com
CData did not get me around it.  I did not want to branch SB source, so I made my own copies of your HtmlParser.java and HtmlTemplateCompiler.java, changed my SB module to overload configureTemplateSystem() and installed the same compilers you had, with the exception of the html parser. Not a great fix, but it got the job done and stopped me from having to branch and then maintain my own version SB in my own maven repo.

Awesome, thanks for fixing that.  Will you be pushing the new version to maven central?

Dhanji R. Prasanna

unread,
Dec 3, 2014, 10:54:21 AM12/3/14
to google-s...@googlegroups.com
Will do the release soon
On Wed, Dec 3, 2014 at 2:45 AM Jared Rodriguez <jrodr...@kitedesk.com> wrote:
CData did not get me around it.  I did not want to branch SB source, so I made my own copies of your HtmlParser.java and HtmlTemplateCompiler.java, changed my SB module to overload configureTemplateSystem() and installed the same compilers you had, with the exception of the html parser. Not a great fix, but it got the job done and stopped me from having to branch and then maintain my own version SB in my own maven repo.

Awesome, thanks for fixing that.  Will you be pushing the new version to maven central?

--

Jared Rodriguez

unread,
Jan 7, 2015, 12:40:55 PM1/7/15
to google-s...@googlegroups.com
Hi Dhanji,

Did you have a chance to push the update with this fix out yet?  I still only see the last version in maven.

Dhanji R. Prasanna

unread,
Jan 7, 2015, 6:08:35 PM1/7/15
to google-s...@googlegroups.com
Sorry Jared I've been on vacation (got married :) without a laptop--I'll push it as soon as I'm back (~5 days).

Apologies!

Jared Rodriguez

unread,
Jan 8, 2015, 5:46:38 AM1/8/15
to google-s...@googlegroups.com
That is awesome man, gratz!!!!!  Have fun on your vacation.    

Jared Rodriguez

unread,
Jan 14, 2015, 5:38:36 AM1/14/15
to google-s...@googlegroups.com
Hi Dhanji,

If you are back from vacation, any chance that you can push the update to maven?

Dhanji R. Prasanna

unread,
Jan 14, 2015, 5:45:59 PM1/14/15
to google-s...@googlegroups.com
Hi Jared,

The release is on its way to central courtesy of Jason Van Zyl.

Thanks!
Dhanji.

On Wed Jan 14 2015 at 2:38:37 AM Jared Rodriguez <jrodr...@kitedesk.com> wrote:
Hi Dhanji,

If you are back from vacation, any chance that you can push the update to maven?

--

Jared Rodriguez

unread,
May 14, 2015, 1:51:33 PM5/14/15
to google-s...@googlegroups.com
Hi Dhanji,

Sorry for the long delay, but my override fix was working for me, so I am just getting back to not using it and using unmodified sitebricks.

Unfortunately, the problem still exists.  Inside of com.google.sitebricks.compiler.HtmlParser.java line 200, there is still just the check for tag.isData() in order to NOT parse sections that should be ignored.  JSoup still returns false for this if the section is a <script> .  

The simple fix is to change 

if (tag.isData()) {

to

if (tag.isData() || tag.getName().equalsIgnoreCase("script") || tag.getName().equalsIgnoreCase("textarea")) {

or something similar.

Dhanji R. Prasanna

unread,
May 17, 2015, 10:01:47 PM5/17/15
to google-s...@googlegroups.com
Hi Jared, I'm sorry to hear that =(

Do you mind submitting a pull request? Then I can test and re-release.
Thank you!

Jared Rodriguez

unread,
May 18, 2015, 1:10:37 PM5/18/15
to google-s...@googlegroups.com
I will try.  I get errors simply checking out the project from github (https://github.com/dhanji/sitebricks.git) and doing a maven a deploy.  I am running maven 3.0.4 and when I run mvn clean install I get the following problems.  I am debugging it now, but any help would be greatly appreciated


[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Sitebricks :: Parent .............................. FAILURE [0.335s]
[INFO] Sitebricks :: Type Conversion ..................... SKIPPED
[INFO] Sitebricks :: Client .............................. SKIPPED
[INFO] Sitebricks :: Annotations ......................... SKIPPED
[INFO] Sitebricks :: Core ................................ SKIPPED
[INFO] Sitebricks :: Extensions .......................... SKIPPED
[INFO] Sitebricks :: Test Support ........................ SKIPPED
[INFO] Sitebricks :: Statistics .......................... SKIPPED
[INFO] Sitebricks :: Channel ............................. SKIPPED
[INFO] Sitebricks :: Acceptance Tests .................... SKIPPED
[INFO] Sitebricks :: Mail Client ......................... SKIPPED
[INFO] Sitebricks :: Options ............................. SKIPPED
[INFO] Sitebricks :: SLF4J Module ........................ SKIPPED
[INFO] Sitebricks :: Persistence ......................... SKIPPED
[INFO] Sitebricks :: Persistence Module (Disk) ........... SKIPPED
[INFO] Sitebricks :: Persistence Module (Redis) .......... SKIPPED
[INFO] Sitebricks :: Persistence Module (SQL) ............ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.016s
[INFO] Finished at: Mon May 18 13:09:16 EDT 2015
[INFO] Final Memory: 8M/183M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.takari.maven.plugins:takari-lifecycle-plugin:1.10.2:install (default-install) on project sitebricks-parent: The plugin io.taka
ri.maven.plugins:takari-lifecycle-plugin:1.10.2 requires Maven version [3.2.1,) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.takari.maven.plugins:takari-lifecycle-plugin:1.10.2:install (default-install)
on project sitebricks-parent: The plugin io.takari.maven.plugins:takari-lifecycle-plugin:1.10.2 requires Maven version [3.2.1,)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:170)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginIncompatibleException: The plugin io.takari.maven.plugins:takari-lifecycle-plugin:1.10.2 requires Maven version [3.2.1,
)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.checkRequiredMavenVersion(DefaultMavenPluginManager.java:283)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:166)
        ... 19 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:

Dhanji R. Prasanna

unread,
May 26, 2015, 1:07:46 AM5/26/15
to google-s...@googlegroups.com
I think you might need Maven 3.2.1+

It builds fine for me.

Dhanji R. Prasanna

unread,
May 26, 2015, 1:08:38 AM5/26/15
to google-s...@googlegroups.com
Sorry about the late/intermittent replies--I'm traveling overseas and internet is spotty where I am.
Reply all
Reply to author
Forward
0 new messages