Skip to content

fix: Key construction in ExtractGoComments#9

Merged
candiduslynx merged 1 commit intocqmainfrom
fix/add-go-comments-wals
Oct 18, 2023
Merged

fix: Key construction in ExtractGoComments#9
candiduslynx merged 1 commit intocqmainfrom
fix/add-go-comments-wals

Conversation

@candiduslynx
Copy link
Copy Markdown

The intended (from README.md) usage of ExtractGoComments(base, path string, commentMap map[string]string) error treats the params as following:

  • base – package import path
  • path – package location on the filesystem
  • commentMap output

If we pass "../" as path param the code will fail to load comments properly because of the path.Join used on the unverified input. Moreover, if the path is the absolute path, the code will join it with base so we end up with keys base + "/" + absPath (cleaned in the path.Clean func, but still).

This PR fixes the behavior in the following way:

  • renaming path to rootPath for better understanding the semantics & not allowing name clashes in the func
  • creating a root variable equal to the absolute path of the rootPath location
  • walking the root path
  • trimming the root prefix of the path prior to joining with the base value

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.

Generate docs from JSON schemas Add descritpions to JSON schemas

1 participant