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

Line is not parsed if added with tabs instead of spaces #6

Closed
areYouLazy opened this issue Feb 25, 2021 · 3 comments
Closed

Line is not parsed if added with tabs instead of spaces #6

areYouLazy opened this issue Feb 25, 2021 · 3 comments

Comments

@areYouLazy
Copy link
Owner

If I manually add a new line to the hosts file in this format:
[ip.ad.dre.ss]\t\t[hostname]\t\t[#comment]
The line is parsed as Comment and not ADDRESS
If the same line is added with the format
[ip.ad.dre.ss]\s\s\s\s\s\s\s\s[hostname]\s\s\s\s\s\s\s\s[#comment]
The line is correctly parsed as ADDRESS

@areYouLazy
Copy link
Owner Author

areYouLazy commented Feb 25, 2021

I think the problem is how we Split the line

tmpParts := strings.Split(strings.TrimSpace(curLine.Trimed[1:]), " ")

Tabs are not handled if split is done in this way

@areYouLazy
Copy link
Owner Author

It seems that using strings.Fields() instead of strings.Split() does the job

strings.Fields() https://golang.org/pkg/strings/#Fields
strings.Split() https://golang.org/pkg/strings/#Split

@areYouLazy
Copy link
Owner Author

Also we should use strings.TrimPrefix() instead of the actual curLine.Trimed[1:] to remove the '#' prefix

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

No branches or pull requests

1 participant