[x3d-public] Need to agree on setContent string encoding in Java (backslashes); X3DJSAIL update posted

Don Brutzman brutzman at nps.edu
Tue Jan 2 01:54:44 PST 2018


John, to simplify: there is no debate necessary of theory versus engineering.  Each example in each encoding is either correct or incorrect.

Final test: does it parse and render on screen as X3D.  The ultimate goal is to put " characters on the display.

I'm not sure that it is ever possible to definitively agree on escape-character syntax solely via an email message, there is too much escaping of the escaping (and sometimes more escaping based on various mail tools).  Need a better escape strategy from this hall of mirrors.  Let's stick to plain-text log outputs to confirm correctness, please.

The X3DJSAIL examples are the most tested in this regard, particularly for the Immel test.  Please identify which example looks incorrect is not passing validation tests:

http://www.web3d.org/specifications/java/X3DJSAIL.html#Examples
http://www.web3d.org/specifications/java/examples/HelloWorldProgram.java
http://www.web3d.org/specifications/java/examples/HelloWorldProgramOutputLog.txt

Reinspecting the log: the various outputs there look pretty good in most cases and most encodings... except am now noticing that Text node values not having backslash characters prior to quote marks.  Ouch!  Sorry to miss that following the most recent improvements last week.

Did some more tracing and testing of regular expressions... still pretty slippery!  Good progress.  Loading of valid inputs looks good.

Here is example X3DJSAIL java code excerpt for XML serialization output:

=============================
String result = new String();
for (String eachValue : value)
{
	// http://www.regexplanet.com/advanced/java/index.html
	// https://www.regular-expressions.info/java.html see "backslash-mess"
	// https://docs.oracle.com/javase/tutorial/java/data/characters.html
	// append another quoted SFString value to MFString output
	result += " \"" + eachValue
		.replaceAll("&","&")      // escape ampersands           in XML attributes
		   .replaceAll("<","<")       // escape    less-than < signs in XML attributes
		   .replaceAll(">",">")       // escape greater-than > signs in XML attributes
		   .replaceAll("'","'")     // escape apostrophes since XML attributes in this output are delimited by apostrophes
		   .replaceAll("\\\\","\\\\")    // escape backslash \ as \\    in XML attributes
		   .replaceAll("\"",  "\\\\\"")  // escape     quote " as \"    in XML attributes
		+ "\"";
}
return (result.trim());
=============================

The "backslash mess" reference above tells the story.  Didn't find that solution in the OReilly regex book (vol 3) or cookbook.

I think this correction fixed regex handling of escaped quote character in XML output for Text node and MFStringObject.  Corrected XML output affects other downstream conversions as well (VRML JSON etc.) in this test chain.  So hopefully a good ripple effect all around.

Anyway, retested and it looks better.  Dare we hope fixed??!!

There are many Immel exemplars in the log.  Tell me which ones you don't like and we'll keep working. Thanks again John.

http://www.web3d.org/specifications/java/examples/HelloWorldProgramOutputLog.txt


On 12/31/2017 7:01 PM, John Carlson wrote:
> Don, we need to agree on setContent string encoding in Java, particularly \’s.: I would also think that \n would be encoded as \n in Java, but I seem to recall some issues with that.
> 
> Don’s Java
> 
>      .addMeta(new metaObject().setName("description").setContent("a script test with embedded \\n between single quotes, a double backslash \\\\\\\\ a backslash \\\\ and a closing quote \"")))
> 
> John’s Java:
> 
>          .addMeta(new metaObject().setName("description").setContent("a script test with embedded \\n between single quotes, a double backslash \\\\ a backslash \\ and a closing quote \"")))
> 
> X3D XML:
> 
>          <meta name='description' content='a script test with embedded \n between single quotes, a double backslash \\\\ a backslash \\ and a closing quote "'/>
> 
> X3D JSON:
> 
>            {
> 
>              "@name":"description",
> 
>              "@content":"a script test with embedded \n between single quotes, a double backslash \\\\ a backslash \\ and a closing quote \""
> 
>            },
> 
> Please advise! More to follow.
> 
> John
> 


all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list