Skip to content

Commit

Permalink
escape \r characters
Browse files Browse the repository at this point in the history
  • Loading branch information
smart-fun committed Dec 10, 2017
1 parent 3333a1a commit 863b411
Show file tree
Hide file tree
Showing 4 changed files with 2,168 additions and 16 deletions.
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -5,6 +5,7 @@
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -24,6 +25,8 @@
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {

private static final String TAG = "ExampleInstrumentedTest";

@Test
public void numbersTest() throws Exception {

Expand Down Expand Up @@ -163,7 +166,7 @@ public void skipAttributeTest() throws Exception {
JSONArray books = library.getJSONArray("book");
int size = books.length();
assertTrue(size == 2);
for(int i=0; i<size; ++i) {
for (int i = 0; i < size; ++i) {
JSONObject book = books.getJSONObject(i);
assertFalse(book.has("id"));
}
Expand Down Expand Up @@ -207,7 +210,7 @@ public void attributeReplacementTest() throws Exception {
JSONObject library = result.getJSONObject("library");
JSONArray books = library.getJSONArray("book");
assertEquals(books.length(), 2);
for(int i=0 ;i<books.length(); ++i) {
for (int i = 0; i < books.length(); ++i) {
JSONObject book = books.getJSONObject(i);
book.getInt("attributeReplacement");
}
Expand Down Expand Up @@ -279,5 +282,34 @@ public void escapeSpecialCharsTest() throws Exception {
}
}

// "\r" characters were not escaped
// RSS feed taken from https://www.bola.net/feed/
@Test
public void rssURLescaped() throws Exception {
Context context = InstrumentationRegistry.getTargetContext();
AssetManager assetManager = context.getAssets();
InputStream inputStream = assetManager.open("rss.xml");

XmlToJson xmlToJson = new XmlToJson.Builder(inputStream, null).build();
inputStream.close();

try {
JSONObject json = xmlToJson.toJson();
JSONObject rss = json.getJSONObject("rss");
JSONObject channel = rss.getJSONObject("channel");
JSONArray items = channel.getJSONArray("item");
for (int i = 0; i < items.length(); ++i) {
JSONObject item = items.getJSONObject(i);
JSONObject enclosure = item.getJSONObject("enclosure");
String url = enclosure.getString("url");
Log.i(TAG, "url: " + url);
}
json.toString();
} catch (JSONException exception) {
exception.printStackTrace();
assertTrue("invalid JSON", false);
}
}


}

0 comments on commit 863b411

Please sign in to comment.