-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[BUG] String.endswith
breaks when used on a string containing UTF-8 characters.
#3903
Comments
@martinvuyk You've done a lot of work already on the utf8 side of String, so you may have already fixed this in one of your PRs🙂 |
@thatstoasty I haven't gotten around to those functions yet, but I think I found the problem. All of that context to explain: fn endswith(
self, suffix: StringSlice, start: Int = 0, end: Int = -1
) -> Bool:
"""Verify if the `StringSlice` end with the specified suffix between
start and end positions.
Args:
suffix: The suffix to check.
start: The start offset from which to check.
end: The end offset from which to check.
Returns:
True if the `self[start:end]` is suffixed by the input suffix.
"""
if len(suffix) > len(self):
return False
if end == -1:
return self.rfind(suffix, start) + len(suffix) == len(self)
return StringSlice[origin](
ptr=self.unsafe_ptr() + start, length=end - start
).endswith(suffix) The line If that's not the case then I'm as lost as you are 😅 |
Improve `startswith()` and `endswith()` This changes these methods to take `StringSlice`, and simplifies their implementation on `String` and `StringLiteral` to simply delegate to `StringSlice`'s implementation of the same operation. Closes #3903. Solves the current CI failure with `check_licences.mojo` passing a `StringSlice` to `String.startswith()`. Co-authored-by: Connor Gray <[email protected]> Closes #3922 MODULAR_ORIG_COMMIT_REV_ID: 8b078da9d23edc4e118dc9854763e0fb69887fba
Bug description
endswith
returns the wrong result when unicode characters are part of the string. The example below should paint a clear picture. This may be fixed in one of the open utf8 PRs already, but I wanted to raise this issue just in case.Steps to reproduce
Repro example:
System information
The text was updated successfully, but these errors were encountered: