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

Improve checking entries in the hostfile #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlannoye
Copy link
Contributor

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.com and the user is setting up example.com it will be skipped and not added to the hostfile.

@zetlen zetlen self-requested a review November 21, 2019 17:31
Copy link
Collaborator

@zetlen zetlen left a comment

Choose a reason for hiding this comment

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

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!

Comment on lines +53 to +61
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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

alias-mac pushed a commit to alias-mac/devcert that referenced this pull request Feb 8, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants