This is an archive of the discontinued LLVM Phabricator instance.

Regex backreference [3/3] Validate backreferences in the constructor.
ClosedPublic

Authored by Mordante on May 25 2019, 11:57 AM.

Details

Summary

This patch enables throwing exceptions for invalid backreferences
in the constructor when using the basic, extended, grep, or egrep grammar.

This fixes bug 34297.

Diff Detail

Event Timeline

Mordante created this revision.May 25 2019, 11:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 25 2019, 11:57 AM

I think you need more diverse tests here.
What about a reference to a pattern that hasn't been defined yet? Is that valid? Something like "\\1(cat)"

Mordante updated this revision to Diff 208740.Jul 9 2019, 10:56 AM
Mordante edited the summary of this revision. (Show Details)

Added more unit tests.
Moved the range validation from D62451 in this patch.

zoecarver added inline comments.
libcxx/include/regex
3541–3542

Doesn't this if statement need braces around it?

libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
21

Not an issue at all, just a small nit: the default value of f is never used.

zoecarver added inline comments.Aug 17 2019, 9:49 AM
libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
32

All the std::regex::extended and std::regex::egrep tests fail for me.

Mordante marked 3 inline comments as done.Aug 17 2019, 11:08 AM
Mordante added inline comments.
libcxx/include/regex
3541–3542

Yes. This is the same location as you spotted in D62451.

libcxx/test/std/re/re.regex/re.regex.construct/bad_backref.pass.cpp
21

Actually the default argument is used in one call. I'll adjust that call and remove the default.

Mordante updated this revision to Diff 215751.Aug 17 2019, 12:53 PM
Mordante marked an inline comment as done.

Fixes the issues found by @zoecarver.
Only the unit tests don't fail for me. Will try to catch @zoecarver on IRC.

Thanks for fixing those issues :) Looking at it more, it looks like the whole patch wasn't applied. Lines 3555 and 3556 were not update based on the diff I downloaded. When was the last time you rebased off master? I will be on IRC for the next few minutes. Otherwise, my IRC bouncer will catch any messages you send me.

After applying both this and D62451, the tests all passed. Does D62452 rely on / is relied on by any other patches?

Friendly ping

Could you please rebase that on top of the latest master?

ldionne requested changes to this revision.Feb 19 2020, 1:00 PM

(requesting changes so it shows up in my review queue)

This revision now requires changes to proceed.Feb 19 2020, 1:00 PM
Mordante updated this revision to Diff 245714.Feb 20 2020, 12:12 PM

Rebased as requested.

ldionne accepted this revision.Feb 20 2020, 3:17 PM

Thanks!

This revision is now accepted and ready to land.Feb 20 2020, 3:17 PM
This revision was automatically updated to reflect the committed changes.