Improve checking entries in the hostfile#38
Improve checking entries in the hostfile#38dlannoye wants to merge 1 commit intodavewasmer:masterfrom
Conversation
zetlen
left a comment
There was a problem hiding this comment.
Thanks for this, it's a really great bugfix. It's ready to merge as-is, but I have one recommendation about making it even more solid. Let me know!
| export function isDomainInHostFile(hostFileContents: string, domain: string): boolean { | ||
| // Do a check for a full match since a string includes can be fooled by | ||
| // a subdomain being present in the host file. | ||
| const isPresent = hostFileContents | ||
| .replace(/\s+/g, " ") | ||
| .split(" ") | ||
| .filter(item => item === domain).length > 0; | ||
| return isPresent; | ||
| } |
There was a problem hiding this comment.
This looks like pretty solid code, but I'm not 100% sure it'll work for all possible hostfile contents, such as tab characters, different encodings, or comments. Maybe it would be easier to bring in a tool like https://www.npmjs.com/package/hostile which has a well-tested hostfile parser.
There was a problem hiding this comment.
This was a pretty quick and dirty way of improving the checking. Your are right that can be fooled by domains in comments, which the previous code had a problem with as well. I'll take a look hostile and see what that looks like to bring in.
Bumps [@types/rimraf](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/rimraf) from 2.0.4 to 3.0.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/rimraf) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Currently the host file check will not add a domain if a subdomain of that domain already exists.
For example if the host file contains
127.0.0.1 sub.example.comand the user is setting upexample.comit will be skipped and not added to the hostfile.