erdemolkun / plist

Automatically exported from code.google.com/p/plist
0 stars 0 forks source link

string which contains an ampersand is not shown correctly #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
if a string object contains an ampersand the text after the ampersand
is missing.

for example:

the plist contains the url http://www.example.com?param1=1234&param2=abcd

after retrieving the string

String url = ((NSDictionary)content).objectForKey("url").toString();

the url is cropped

http://www.example.com?param1=1234

I am using revison 46.

Original issue reported on code.google.com by claudia....@gmail.com on 31 Oct 2011 at 2:34

GoogleCodeExporter commented 9 years ago
It would help if you could attach a full plist file that is parsing incorrectly.

Perhaps your problem has to do with the fact that ampersands must be escaped in 
xml.  For example, you can't do this:

<string>http://www.example.com?param1=1234¶m2=abcd</string>

you must instead do this:

<string>http://www.example.com?param1=1234&param2=abcd</string>

I'm not sure if that is your problem, though.  I get an exception if I don't 
escape the ampersand, not a string truncation.

Original comment by keith.ra...@gmail.com on 1 Nov 2011 at 4:30

GoogleCodeExporter commented 9 years ago
Also if  a stringobject contains ' the text from the '&' is missing 

Is this same issue?

Original comment by durkjae....@gmail.com on 2 Nov 2011 at 1:09

GoogleCodeExporter commented 9 years ago
@durkjae: Probably - a string with "'" in it should be written as "&apos;" in 
the xml.  In any case, I don't get an error when I do that, "'" gets translated 
back into a single quote just fine when I try it.

Please, please, please!  Attach the plist file you're having trouble with.  
Makes debugging so much easier.

p.s. you probably shouldn't be typing xml - use an xml writer app (or this 
library) which will do the escaping for you.

Original comment by keith.ra...@gmail.com on 2 Nov 2011 at 4:09

GoogleCodeExporter commented 9 years ago
@keith: 

the ampersand is correctly escaped (&)

every text that contains an ampersand will be cropped (you can try it for 
yourself)

i think the issue has something to do with the dom parser

Original comment by claudia....@gmail.com on 3 Nov 2011 at 1:06

GoogleCodeExporter commented 9 years ago
I had use this library(r45, r46) on Android 2.2 (API 8)

following data (refer attacted file) for parsing

...
 <key>filepath</>
<string>Girl's Generation</string>
...

String filepath = rootDict.objectForKey("filepath").toString();

result from above code

The filepath has "Girl".  Not "Girl's Generation"

Original comment by durkjae....@gmail.com on 3 Nov 2011 at 3:36

Attachments:

GoogleCodeExporter commented 9 years ago
Hmm, works fine for me on both OS X and Windows.  Must be something up with the 
Android XML parser.

Original comment by keith.ra...@gmail.com on 3 Nov 2011 at 4:49

GoogleCodeExporter commented 9 years ago
This thread may have something to do with it: 
http://stackoverflow.com/questions/1973483/android-xml-parsing-omitting-amp

We are just grabbing the first child of <string> from the parser (see 
XMLPropertyListParser.java:169).  If the Android XML parser is returning three 
chunks of text, we'd miss the last two.

I'll have to think about the right way to fix this.  This "feature" might 
affect more than just <string>.

Original comment by keith.ra...@gmail.com on 3 Nov 2011 at 4:56

GoogleCodeExporter commented 9 years ago
Here's a bug filed against Android about this: 
http://code.google.com/p/android/issues/detail?id=2607

Upshot: try adding "docBuilderFactory.setCoalescing(true);" right after 
"docBuilderFactory.setIgnoringComments(true);" in XMLPropertyListParser.java:54

Let me know if that works.  Sorry I can't try it myself, I don't have an 
Android environment to test on.

Original comment by keith.ra...@gmail.com on 3 Nov 2011 at 5:08

GoogleCodeExporter commented 9 years ago
Oh! works fine on Android.

Thanks for your advice.

...
private static synchronized void initDocBuilderFactory() throws 
ParserConfigurationException {
        docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilderFactory.setIgnoringComments(true);
        docBuilderFactory.setCoalescing(true); 
    }
...

Original comment by durkjae....@gmail.com on 4 Nov 2011 at 2:14

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r50.

Original comment by kei...@alum.mit.edu on 4 Nov 2011 at 3:03

GoogleCodeExporter commented 9 years ago
I committed the fix, revision 50.

Original comment by kei...@alum.mit.edu on 4 Nov 2011 at 3:05

GoogleCodeExporter commented 9 years ago
I am using rev52 and I am still seeing this problem. 

In the attached plist if you go to
AllSports > Item 0 > AllFeeds > Item 0 > FeedUrl you will see 
http://www.meangreensports.com/rss.dbml?db_oem_id=1800&media=results

but when ever I do an objectForKey on "FeedUrl" I get

http://www.meangreensports.com/rss.dbml?db_oem_id=1800

everything after the & is cut off. Any suggestions?

Original comment by CesarFer...@gmail.com on 23 Nov 2011 at 8:19

Attachments:

GoogleCodeExporter commented 9 years ago
Please check whether you are actually using r52.

If you really are, please check whether the attached version works.

In the attached version all child nodes of a NSObject tag are joined together 
to form the string. Normally the whole string should be identified as one node 
by the parser. But the Android parser seems to work incorrectly in this regard.

Original comment by daniel.dreibrodt on 23 Nov 2011 at 9:08

Attachments:

GoogleCodeExporter commented 9 years ago
Here's the Android bug about this: 
http://code.google.com/p/android/issues/detail?id=2607

Sounds like there's no way to force coalescing of entities (unlike CDATA 
sections, which is what setCoalescing is for).

Original comment by keith.ra...@gmail.com on 23 Nov 2011 at 11:31

GoogleCodeExporter commented 9 years ago
@daniel.dreibrodt looks like the attached jar file you provided did the trick!! 
Thanks!! 

Original comment by CesarFer...@gmail.com on 24 Nov 2011 at 2:02

GoogleCodeExporter commented 9 years ago
I commited the proper fix with r54.

Original comment by daniel.dreibrodt on 24 Nov 2011 at 7:51