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

Correção do bug de encoding do método 'track' #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/correios.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var request = require('request'),
cheerio = require('cheerio'),
querystring = require('querystring'),
iconv = require('iconv-lite'),
xml2js = require('xml2js');

// really don't wanna do this for all strings...
Expand Down Expand Up @@ -127,14 +128,16 @@ var correios = module.exports = {

var url = CorreiosOptions.baseUrls.track + code;

return request( url, {}, function( error, response, body ) {
return request( url, { encoding: null}, function( error, response, body ) {

if ( error )
return callback( error );

if ( response.statusCode != 200 )
return callback( new Error('Correios error -> http status code:' + response.statusCode) );

body = iconv.decode(body, 'iso-8859-1');

// parse html
$ = cheerio.load( body, {
lowerCaseTags: true
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"keywords": [ "correios", "track", "muamba", "sedex", "pac", "calculo" ],

"version": "0.0.4",
"version": "0.0.5",

"author": "Felipe K. De Boni <[email protected]>",

Expand All @@ -16,6 +16,7 @@
"dependencies": {
"request": ">=2.11.1",
"cheerio": ">=0.10.0",
"iconv-lite": "^0.4.13",
"xml2js": ">=0.2.0"
},

Expand Down