Skip to content

hotfix: use strings.TrimPrefix() for relative paths - #145

Merged
niemeyer merged 4 commits into
canonical:mainfrom
rebornplusplus:hotfix/relpath-trims-prefix
Jul 4, 2024
Merged

niemeyer merged 4 commits into
canonical:mainfrom
rebornplusplus:hotfix/relpath-trims-prefix

Conversation

@rebornplusplus

Copy link
Copy Markdown

Use strings.TrimPrefix() for relative paths instead of strings.TrimLeft(), since TrimLeft takes in a cutset instead of a prefix sub-string.

In this particular case, if the --root (output) directory is /tmp/foo and we are determining the relative path for /tmp/foo/tmp-foo, the relative path would result in /-foo since /tmp/foo/tmp would be matched by the /tmp/foo/ cutset.

This results in a flawed map of knownPaths inside slicer.go, which is only checked by the mutation script functions such as content.list().

This commit fixes said bug.

Use ``strings.TrimPrefix()`` for relative paths instead of
``strings.TrimLeft()``, since ``TrimLeft`` takes in a cutset instead of
a prefix sub-string.

In this particular case, if the ``--root`` (output) directory is
``/tmp/foo`` and we are determining the relative path for
``/tmp/foo/tmp-foo``, the relative path would result in ``/-foo`` since
``/tmp/foo/tmp`` would be matched by the ``/tmp/foo/`` cutset.

This results in a flawed map of ``knownPaths`` inside slicer.go, which
is only checked by the mutation script functions such as
``content.list()``.

This commit fixes said bug.
@rebornplusplus rebornplusplus added Simple Nice for a quick look on a minute or two Priority Look at me first labels Jul 3, 2024
@rebornplusplus
rebornplusplus requested a review from letFunny July 3, 2024 08:55

@letFunny letFunny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you Rafid for doing your due diligence and for submitting the bugfix so quickly!

Comment thread internal/slicer/slicer_test.go Resolved
Comment thread internal/slicer/slicer_test.go Resolved
@rebornplusplus
rebornplusplus requested a review from letFunny July 3, 2024 09:32

@letFunny letFunny left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, LGTM!

@cjdcordeiro cjdcordeiro left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix @rebornplusplus .

@cjdcordeiro
cjdcordeiro requested a review from niemeyer July 3, 2024 11:00

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch, thanks Rafid.

@niemeyer
niemeyer merged commit 504ad63 into canonical:main Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority Look at me first Simple Nice for a quick look on a minute or two

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants