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

regression: ^ incorrect when start != 0 #64

Closed
timotheecour opened this issue May 1, 2020 · 6 comments · Fixed by #66
Closed

regression: ^ incorrect when start != 0 #64

timotheecour opened this issue May 1, 2020 · 6 comments · Fixed by #66
Labels
bug Something isn't working

Comments

@timotheecour
Copy link
Contributor

timotheecour commented May 1, 2020

/cc @nitely
I was having a weird error in some program until I traced it back to a regression in nim-regex:

when true: # D20200501T000945
  import pkg/regex
  proc main()=
    let src = """xabc"""
    let start = 1
    var m: RegexMatch
    let regx = "^abc$".re
    let ok = find(src, regx, m, start = start)
    doAssert ok
  main()

ff6ab82: works
master (92ff73c) : fails

git bisect says it's 92ff73c

@nitely
Copy link
Owner

nitely commented May 1, 2020

That's re and nre behaviour. The workaround is to use match(txt, re"abc", m, start=1), or to add openArray[char] support so you can pass toOpenArray(src, 1, src.len-1) and start=0.

@timotheecour
Copy link
Contributor Author

timotheecour commented May 1, 2020

  • That's re and nre behaviour
    then it seems like a bug that we should report in nim repo

  • match(txt, re"abc", m, start=1) wouldn't work if my regex is "^abc" instead of "^abc$" though IIUC

  • as a workaround, how about adding a simple bool flag, treatStartAsStart ?

@nitely
Copy link
Owner

nitely commented May 1, 2020

then it seems like a bug that we should report in nim repo

Thank you. I think it's a bug too, but I was trying to convince myself it's a feature :P.

match(txt, re"abc", m, start=1) wouldn't work if my regex is "^abc" instead of "^abc$" though IIUC

Yeah. That's why I suggested toOpenArray.

Since no other regex library has re/nre behaviour, and no one has reported the previous behaviour to be wrong, I'll label this as a bug and fix it.

@nitely nitely added the bug Something isn't working label May 1, 2020
nitely added a commit that referenced this issue May 7, 2020
@nitely nitely closed this as completed in #66 May 7, 2020
nitely added a commit that referenced this issue May 7, 2020
* treat start as text[start..^1], fixes #64

* tests
@timotheecour
Copy link
Contributor Author

thanks for the fix! I've submitted nim-lang/Nim#14284

@timotheecour
Copy link
Contributor Author

@nitely so in light of nim-lang/Nim#14284 should we re-open to match re/nre behavior? sorry I was wrong initially on this one, the start + preserving context argument (eg nim-lang/Nim#14284 (comment) or nim-lang/Nim#14284 (comment)) is convincing

nitely added a commit that referenced this issue May 18, 2020
@nitely
Copy link
Owner

nitely commented May 18, 2020

Yes, I'll revert the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants