Skip to content

Commit 4680f98

Browse files
committed
Fix bug in rssv2 parser for channel image parsing
1 parent d05b78e commit 4680f98

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-rss-parser",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "React Native compatible package to parse RSS feeds",
55
"main": "index.js",
66
"scripts": {

parsers/rssv2.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,26 @@ function getChannelCategories(node) {
9090
}
9191

9292
function getChannelImage(node) {
93+
const imageNodes = utils.getChildElements(node, 'image');
94+
95+
if (imageNodes.length === 0) {
96+
return {
97+
url: undefined,
98+
title: undefined,
99+
description: undefined,
100+
width: undefined,
101+
height: undefined
102+
};
103+
}
104+
105+
const imageNode = imageNodes[0];
106+
93107
return {
94-
url: utils.getElementAttributeContent(node, 'image', 'url'),
95-
title: utils.getElementAttributeContent(node, 'image', 'title'),
96-
description: utils.getElementAttributeContent(node, 'image', 'description'),
97-
width: utils.getElementAttributeContent(node, 'image', 'width'),
98-
height: utils.getElementAttributeContent(node, 'image', 'height'),
108+
url: utils.getElementTextContent(imageNode, 'url'),
109+
title: utils.getElementTextContent(imageNode, 'title'),
110+
description: utils.getElementTextContent(imageNode, 'description'),
111+
width: utils.getElementTextContent(imageNode, 'width'),
112+
height: utils.getElementTextContent(imageNode, 'height'),
99113
};
100114
}
101115

test/samples/reuters.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/samples/rssv2.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/test-feeds.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ describe('when parse reuters', function() {
1111
assert.equal(result.links.length, 1);
1212
assert.equal(result.links[0].url, 'http://www.reuters.com');
1313
assert.equal(result.description, 'Reuters.com is your source for breaking news, business, financial and investing news, including personal finance and stocks. Reuters is the leading global provider of news, financial information and technology solutions to the world\'s media, financial institutions, businesses and individuals.');
14+
assert.equal(result.image.url, 'http://www.reuters.com/resources_v2/images/reuters125.png');
15+
assert.equal(result.image.title, 'Reuters News');
16+
assert.equal(result.image.width, '120');
17+
assert.equal(result.image.height, '35');
18+
assert.equal(result.language, 'en-us');
19+
assert.equal(result.lastUpdated, 'Tue, 30 Jan 2018 17:54:13 -0500');
20+
assert.equal(result.copyright, 'All rights reserved. Users may download and print extracts of content from this website for their own personal and non-commercial use only. Republication or redistribution of Reuters content, including by framing or similar means, is expressly prohibited without the prior written consent of Reuters. Reuters and the Reuters sphere logo are registered trademarks or trademarks of the Reuters group of companies around the world. © Reuters 2018');
1421
assert.equal(result.items.length, 10);
1522
assert.equal(result.items[0].title, 'U.S. general says North Korea not demonstrated all components of ICBM');
1623
assert.equal(result.items[0].categories.length, 1);
1724
assert.equal(result.items[0].categories[0].name, 'worldNews');
25+
assert.equal(result.items[1].title, 'Publication of Russia \'oligarch list\' may affect investors: group');
26+
assert.equal(result.items[1].categories.length, 1);
27+
assert.equal(result.items[1].categories[0].name, 'worldNews');
1828
});
1929
});
2030
});

test/test-parser-rssv2.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('when rss parse', function() {
2121
assert.equal(result.lastPublished, undefined);
2222
assert.equal(result.categories.length, 1);
2323
assert.equal(result.categories[0].name, '1765');
24-
assert.equal(result.image.url, "http://www.example.com/image.jpg");
24+
assert.equal(result.image.url, 'http://www.example.com/image.jpg');
25+
assert.equal(result.image.title, 'test image');
2526
assert.equal(result.authors.length, 1);
2627
assert.equal(result.authors[0].name, 'dave@userland.com');
2728
assert.equal(result.items.length, 9);

0 commit comments

Comments
 (0)