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

fix(parser): add whitespace infinitely to headers #13

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ type Document struct {
Valid bool
}

var caser = cases.Title(language.Und)
var metaDataRegex = regexp.MustCompile("^# @")
var (
caser = cases.Title(language.Und)
metaDataRegex = regexp.MustCompile("^# @")
)

func parseHTTPLine(line string) (method string, url string, version string) {
method = ""
Expand Down Expand Up @@ -120,10 +122,10 @@ func parseSection(section string, document *Document) Section {
} else if in_header {
if strings.Contains(line, ":") {
httpVersion := parsedSection.Version
line = strings.Trim(line, " ")
line = strings.TrimSpace(line)
splits := strings.Split(line, ":")
headerName := strings.ToLower(splits[0])
headerValue := strings.Join(splits[1:], ":")
headerValue := strings.TrimSpace(strings.Join(splits[1:], ":"))
if httpVersion != "HTTP/2" && httpVersion != "HTTP/3" {
headerName = caser.String(headerName)
}
Expand Down Expand Up @@ -232,7 +234,7 @@ func parser(filepath string, flags config.ConfigFlags) {
if flags.Verbose {
log.Info("Writing", filepath, documentString)
}
err := os.WriteFile(filepath, []byte(documentString), 0644)
err := os.WriteFile(filepath, []byte(documentString), 0o644)
if err != nil {
log.Fatal("Error writing file", "error", err)
}
Expand All @@ -245,5 +247,4 @@ func parser(filepath string, flags config.ConfigFlags) {
}
}
}

}
}
Loading