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

std.mem.indexOfPos should return start_index when needle length is zero #10216

Closed
mbolis opened this issue Nov 25, 2021 · 0 comments · Fixed by #10220
Closed

std.mem.indexOfPos should return start_index when needle length is zero #10216

mbolis opened this issue Nov 25, 2021 · 0 comments · Fixed by #10220
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@mbolis
Copy link

mbolis commented Nov 25, 2021

Zig Version

0.9.0-dev.1712+9836f1b2f

Steps to Reproduce

Search for an empty slice inside another:

const std = @import("std");
const indexOfPos = std.mem.indexOfPos;
const expect = std.testing.expect;

test "should return start index" {
    const index = indexOfPos(u8, "abracadabra", 5, "") orelse unreachable;
    try expect(index == 5); // fails
}

Expected Behavior

I expect an empty slice to be always found exactly at the specified start index.

Actual Behavior

The indexOfPos function always returns 0 if the needle has no length.

@mbolis mbolis added the bug Observed behavior contradicts documented or intended behavior label Nov 25, 2021
@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. labels Nov 25, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants