Skip to content

Commit

Permalink
Issue #23 - non-latin characters
Browse files Browse the repository at this point in the history
- Allow setting rssEncoding in options array, defaults to UTF-8
- Move from iconv-lite to iconv, more reliable
  • Loading branch information
aidvu committed Aug 28, 2014
1 parent 0efcfac commit f7228dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ node_js:
- 0.11
- 0.10
- 0.8

14 changes: 8 additions & 6 deletions lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var xml2js = require('xml2js'),
_ = require('underscore'),
request = require('request'),
URL = require('url'),
iconv = require('iconv-lite');
Iconv = require('iconv').Iconv;
/**
All you need to do is send a feed URL that can be opened via fs
Options are optional, see xml2js for extensive list
Expand All @@ -21,7 +21,9 @@ function parseURL(feedURL, options, callback) {
jar: false,
proxy: false,
followRedirect: true,
timeout: 1000 * 30
timeout: 1000 * 30,
encoding: null,
rssEncoding: 'UTF-8'
};
options = _.extend(defaults, options);
//check that the protocal is either http or https
Expand All @@ -40,9 +42,9 @@ function parseURL(feedURL, options, callback) {
if (response.statusCode >= 400) {
callback("Failed to retrieve source! Invalid response code (" + response.statusCode + ")!", null);
} else {
var encodedXml = iconv.decode(new Buffer(xml), 'ISO-8859-1');
parseString(encodedXml, options, callback);
//issues22
var iconv = new Iconv(options.rssEncoding, 'UTF-8');
xml = iconv.convert(new Buffer(xml)).toString();
parseString(xml, options, callback);
}
} else {
callback("Failed to retrieve source! No response code!!", null);
Expand Down Expand Up @@ -341,4 +343,4 @@ var DateHelper = {
}
return 'over ' + Math.floor(distance_in_minutes / 525960) + ' years';
}
};
};
15 changes: 11 additions & 4 deletions npm-shrinkwrap.json

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

10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"name": "rssparser",
"version": "0.0.9",
"version": "0.0.10",
"author": "Arjunkumar Krishnamoorthy",
"contributors": [
"Javier Scappini",
"Andrija Vucinic"
],
"description": "rssparser is an all purpose RSS/ATOM feed parser that parses feeds into a JSON format.",
"keywords": [
"rss",
Expand All @@ -20,7 +24,7 @@
"xml2js": ">=0.2.0",
"request": ">=2.9.3",
"underscore": ">=1.3.3",
"iconv-lite": ">=0.4.4"
"iconv": ">=2.1.4"
},
"devDependencies": {
"vows": "*"
Expand All @@ -31,6 +35,6 @@
"main": "./lib/feed.js",
"readme": "node-rssparser",
"readmeFilename": "README.md",
"_id": "rssparser@0.0.9",
"_id": "rssparser@0.0.10",
"_from": "rssparser"
}

0 comments on commit f7228dd

Please sign in to comment.