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

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

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

rebornplusplus
Copy link
Member

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
Copy link
Collaborator

@letFunny letFunny left a comment

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!

internal/slicer/slicer_test.go Outdated Show resolved Hide resolved
internal/slicer/slicer_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@letFunny letFunny left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

Copy link
Collaborator

@cjdcordeiro cjdcordeiro left a comment

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
Copy link
Contributor

@niemeyer niemeyer left a comment

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
14 checks passed
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