Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string which contains an ampersand is not shown correctly #21

Closed
GoogleCodeExporter opened this issue May 23, 2015 · 16 comments
Closed

Comments

@GoogleCodeExporter
Copy link

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
Copy link
Author

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
Copy link
Author

Also if  a string�object 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
Copy link
Author

@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
Copy link
Author

@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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

This issue was closed by revision r50.

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

I committed the fix, revision 50.

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

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

@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
Copy link
Author

I commited the proper fix with r54.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant