Skip to content

fix: Key construction in ExtractGoComments #9

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

Merged
merged 1 commit into from
Oct 18, 2023

Conversation

candiduslynx
Copy link

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