Skip to content

replace <str>.length with Buffer.byteLength(<str>) - #223

Merged
th0r merged 2 commits into
masterfrom
use-buffer-bytelength
Mar 2, 2019
Merged

th0r merged 2 commits into
masterfrom
use-buffer-bytelength

Conversation

@hulkish

@hulkish hulkish commented Nov 15, 2018 •

Copy link
Copy Markdown
Contributor

Some chars represent a byte length greater than 1. This means string length could report incorrect parsedSize, for bundles - if any special chars are used. More on this here.

Some chars represent a byte length greater than 1. This means string length could report incorrect `statSize` if any special chars are used. More on this [here](https://sankhs.com/2016/03/17/content-length-http-headers/)
@EugeneHlushko

Copy link
Copy Markdown

Looks legit, do you think you could add an auto test to cover this case?

@valscion

valscion commented Nov 16, 2018 •

Copy link
Copy Markdown
Collaborator

Hi, thanks for this PR! @EugeneHlushko has a point — it would be nice if we could have a test to cover this case.

You can take a look into test/stats/with-module-concatenation-info/ how there's both a stats.json generated by webpack and the bundle.js it represents. The expected values webpack-bundle-analyzer would report are in expected-chart-data.js.

This is how the test is ran:

https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/d14528452108988ec6fe5ddd069bbdbd704d0b67/test/analyzer.js#L31-L37

@hulkish

hulkish commented Nov 16, 2018

Copy link
Copy Markdown
Contributor Author

@valscion can you point me in the right direction for this? Im trying to get an idea of how i am intended to generate the fixture for this test?

@valscion

Copy link
Copy Markdown
Collaborator

The best bet might be to create a small reproduction repository with plain webpack and generate a stats.json object and output bundle from there. Supply that output to the basis of your new test and test that the expected sizes match what you want.

@hulkish

hulkish commented Nov 16, 2018

Copy link
Copy Markdown
Contributor Author

@valscion that makes sense, thank you.

I guess I was looking for a script that creates one for me, or something lol

@hulkish

hulkish commented Nov 17, 2018

Copy link
Copy Markdown
Contributor Author

@valscion @EugeneHlushko will this do it?

@th0r
th0r merged commit c0f0165 into master Mar 2, 2019
@th0r
th0r deleted the use-buffer-bytelength branch March 2, 2019 06:25
@th0r

th0r commented Mar 2, 2019 •

Copy link
Copy Markdown
Contributor

@hulkish thanks, merged! Sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants