Skip to content

Commit

Permalink
fix(route): people charset decoding (#16734) (#16743)
Browse files Browse the repository at this point in the history
  • Loading branch information
cieons committed Sep 13, 2024
1 parent 810aae3 commit 487c046
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/routes/people/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ async function handler(ctx) {
responseType: 'buffer',
});

const encoding = site === 'www' ? 'gbk' : 'utf-8';
const decodedResponse = iconv.decode(response, encoding);
// not seen Content-Type in response headers
// try to parse charset from meta tag
let decodedResponse = iconv.decode(response, 'utf-8');
const parsedCharset = decodedResponse.match(/<meta.*?charset=["']?([^"'>]+)["']?/i);
const encoding = parsedCharset ? parsedCharset[1].toLowerCase() : 'utf-8';
decodedResponse = encoding === 'utf-8' ? decodedResponse : iconv.decode(response, encoding);
const $ = load(decodedResponse);

$('em').remove();
Expand Down

0 comments on commit 487c046

Please sign in to comment.