Skip to content

Conversation

@jake-kramer
Copy link
Contributor

This fixes a bug where the logic in handleSanitizedLabel was not properly executed. The code would modify the slice itself, but this new modified slice was never returned up the call stack.

This fixes a bug where the logic in `handleSanitizedLabel` was
not properly executed. The code would modify the slice itself,
but this new modified slice was never returned up the call stack.
@jake-kramer jake-kramer marked this pull request as ready for review December 3, 2025 14:27
@marcsanmi marcsanmi requested a review from simonswine December 3, 2025 14:37
Copy link
Contributor

@marcsanmi marcsanmi left a comment

Choose a reason for hiding this comment

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

AFAIU, the modified length wasn't being propagated back to the callers, was it?

LGTM

@marcsanmi
Copy link
Contributor

cc @simonswine you might want to take a look as well.

@jake-kramer
Copy link
Contributor Author

AFAIU, the modified length wasn't being propagated back to the callers, was it?

LGTM

Yes exactly, here:

if found {
if newSlice[insertIdx].Value == newLabel.Value {
// Same name and value we are done and can just return newSlice
return newSlice, origIdx, nil
} else {
// Same name, different value - error
return nil, 0, NewErrorf(DuplicateLabelNames,
DuplicateLabelNamesAfterSanitizationErrorMsg,
phlaremodel.LabelPairsString(ls), newName, origName)
}
}
// Insert the new label at correct position
newSlice = slices.Insert(newSlice, insertIdx, newLabel)
finalIdx := insertIdx
if insertIdx >= origIdx {
finalIdx = origIdx
}
copy(ls, newSlice)
return ls[:len(newSlice)], finalIdx, nil

Copy link
Contributor

@simonswine simonswine left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks for catching and fixing this, it is amazing how many bugs we have found in this piece of code.

I think ew can merge this as is, but probably we should rename ValidateLabels to SanitizeLabels, as its name doesn't suggest, it is a mutation operation.

@jake-kramer
Copy link
Contributor Author

It will soon be just validation since the sanitization logic will be removed with the utf8 label name work

@jake-kramer jake-kramer merged commit 409e245 into main Dec 4, 2025
21 checks passed
@jake-kramer jake-kramer deleted the fix-label-sanitization branch December 4, 2025 21:16
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.

3 participants