Skip to content

fix(readMultipartFormData): handle utf8 encoding for name and filename#416

Merged
pi0 merged 6 commits intoh3js:mainfrom
zhiyuanzmj:feat/filename-utf8
Jul 24, 2023
Merged

fix(readMultipartFormData): handle utf8 encoding for name and filename#416
pi0 merged 6 commits intoh3js:mainfrom
zhiyuanzmj:feat/filename-utf8

Conversation

@zhiyuanzmj
Copy link
Copy Markdown
Contributor

After I uploaded a file with a Chinese name:

20xx年xx月xx日一号楼电表数据模版.xlsx

the filename was parsed as ISO-8859-1 encoding:

20xxå¹´xxæ__xxæ_¥ä¸_å_·æ¥¼ç_µè¡¨æ_°æ_®æ¨¡ç__.xlsx

So I used Buffer to convert it to UTF-8.

let filename = "20xxå¹´xxæxxæ¥ä¸å·æ¥¼çµè¡¨æ°æ®æ¨¡ç.xlsx";
let buffer = Buffer.from(filename, 'latin1');
filename = buffer.toString('utf8');
console.log(filename);

@Hebilicious Hebilicious added the enhancement New feature or request label Jun 30, 2023
@Hebilicious Hebilicious self-assigned this Jun 30, 2023
@Hebilicious Hebilicious self-requested a review June 30, 2023 17:54
Copy link
Copy Markdown
Contributor

@Hebilicious Hebilicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me @pi0

@Hebilicious Hebilicious requested a review from pi0 July 5, 2023 09:25
@pi0 pi0 changed the title feat(multipart-form-data): use UTF-8 format to prevent garbled filename fix(readBody): handle filename encoding for multipart-form-data Jul 24, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 24, 2023

Codecov Report

Merging #416 (0185754) into main (ed3ae90) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #416      +/-   ##
==========================================
+ Coverage   78.36%   78.38%   +0.02%     
==========================================
  Files          26       26              
  Lines        2792     2795       +3     
  Branches      408      407       -1     
==========================================
+ Hits         2188     2191       +3     
  Misses        604      604              
Impacted Files Coverage Δ
src/utils/internal/multipart.ts 97.40% <100.00%> (+0.05%) ⬆️

@pi0 pi0 added bug Something isn't working needs reproduction and removed enhancement New feature or request labels Jul 24, 2023
@pi0 pi0 changed the title fix(readBody): handle filename encoding for multipart-form-data fix(readMultipartFormData): handle filename encoding Jul 24, 2023
@pi0 pi0 changed the title fix(readMultipartFormData): handle filename encoding fix(readMultipartFormData): handle utf8 encoding for name and filename Jul 24, 2023
Copy link
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit 78aec63 into h3js:main Jul 24, 2023
@pi0 pi0 mentioned this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants