gcjwebplugin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcjwebplugin-devel] two parsing buglets


From: Tom Tromey
Subject: [Gcjwebplugin-devel] two parsing buglets
Date: 05 Jul 2005 18:42:31 -0600

This applet was pointed out to me on irc:

  http://ktown.kde.org/~endres/worldwide/example.html

The HTML is very short:

<html>
<body><h1>WorldWide!</h1>
<applet
    ARCHIVE = "worldwide-applet.jar"
    CODE = "org.kde.worldwide.Applet"
    ALT = "WorldWide browser applet"
    NAME = WorldWide
    WIDTH = 600 HEIGHT = 360>
</body>
</html>


This reveals two buglets.

First, the AppletTag constructor didn't return if it hit TT_EOF.
Second, an unclosed tag was not recognized; while bogus, the JDK
still handles this and it seems like we ought to as well for bug
compatibility.

I'm not sure but I would imagine this is valid:

<applet blahblahblah />

... and it doesn't seem to me that our parsing code handles this
properly either.


For some reason, we can see widthStr == null or heightStr == null as
well.  The appended patch also "fixes" this.  I didn't look to see why
these end up null -- that seems wrong to me as the HTML clearly has
this info.  Perhaps because these are being parsed as numbers and not
strings?

Comments?


FWIW debugging this was surprisingly hard, since it was mostly running
as bytecode.  I hacked a build from .java->native, which made it
somewhat simpler; only then gdb decided that it wouldn't let me print
most objects :-(

Tom

Index: ChangeLog
from  Tom Tromey  <address@hidden>

        * src/gnu/gcjwebplugin/AppletTag.java (AppletTag): Handle
        premature EOF from stream tokenizer.
        (parseNextTag): Handle EOF by returning the last seen tag.
        (getSize): Handle case where widthStr or heightStr is null.

Index: src/gnu/gcjwebplugin/AppletTag.java
===================================================================
RCS file: 
/cvsroot/gcjwebplugin/gcjwebplugin/src/gnu/gcjwebplugin/AppletTag.java,v
retrieving revision 1.20
diff -u -r1.20 AppletTag.java
--- src/gnu/gcjwebplugin/AppletTag.java 24 Aug 2004 13:34:41 -0000 1.20
+++ src/gnu/gcjwebplugin/AppletTag.java 6 Jul 2005 00:44:51 -0000
@@ -1,5 +1,5 @@
 /* AppletTag.java - representation of an HTML APPLET tag
-   Copyright (C) 2003, 2004  Thomas Fitzsimmons <address@hidden>
+   Copyright (C) 2003, 2004, 2005  Thomas Fitzsimmons <address@hidden>
 
    This file is part of GCJ Applet Viewer.
 
@@ -108,6 +108,9 @@
 
     while (tagTokenizer.nextToken() != '>')
       {
+       if (tagTokenizer.ttype == StreamTokenizer.TT_EOF)
+         break;
+
        if (tagTokenizer.ttype == StreamTokenizer.TT_WORD)
          {
            if (tagTokenizer.sval.equals("name"))
@@ -422,6 +425,16 @@
          }
        token = tagTokenizer.nextToken();
       }
+
+    // If we hit EOF, just go ahead with whatever we've got.  Some
+    // pages don't properly terminate; besides which our parser is a
+    // bit bogus anyway.
+    if (currentTag != null)
+      {
+       currentTag.parseArchives();
+       return currentTag;
+      }
+
     return null;
   }
 
@@ -436,42 +449,46 @@
   public static Dimension getSize (AppletTag tag)
   {
     NumberFormat numberFormat;
-    Dimension size = new Dimension();
+    Dimension size = new Dimension(320, 200);
 
     try
       {
        String widthStr = (String) tag.parameters.get("width");
 
-       if (widthStr.charAt(widthStr.length() - 1) == '%')
-         numberFormat = NumberFormat.getPercentInstance(Locale.US);
-       else
-         numberFormat = NumberFormat.getInstance(Locale.US);
+       if (widthStr != null)
+         {
+           if (widthStr.charAt(widthStr.length() - 1) == '%')
+             numberFormat = NumberFormat.getPercentInstance(Locale.US);
+           else
+             numberFormat = NumberFormat.getInstance(Locale.US);
 
-       // FIXME: Handle percentage somehow.
-       size.width = numberFormat.parse(widthStr).intValue();
+           // FIXME: Handle percentage somehow.
+           size.width = numberFormat.parse(widthStr).intValue();
+         }
       }
     catch (ParseException e)
       {
        // Use default.
-       size.width = 320;
       }
 
     try
       {
        String heightStr = (String) tag.parameters.get("height");
 
-       if (heightStr.charAt(heightStr.length() - 1) == '%')
-         numberFormat = NumberFormat.getPercentInstance(Locale.US);
-       else
-         numberFormat = NumberFormat.getInstance(Locale.US);
+       if (heightStr != null)
+         {
+           if (heightStr.charAt(heightStr.length() - 1) == '%')
+             numberFormat = NumberFormat.getPercentInstance(Locale.US);
+           else
+             numberFormat = NumberFormat.getInstance(Locale.US);
 
-       // FIXME: Handle percentage somehow.
-       size.height = numberFormat.parse(heightStr).intValue();
+           // FIXME: Handle percentage somehow.
+           size.height = numberFormat.parse(heightStr).intValue();
+         }
       }
     catch (ParseException e)
       {
        // Use default.
-       size.height = 200;
       }
 
     return size;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]