Modify

Ticket #2157 (closed Bugs: fixed)

Opened 6 years ago

Last modified 6 years ago

Xpressive end-of-line match broken

Reported by: Simon Steele <s.steele@…> Owned by: eric_niebler
Milestone: Boost 1.36.0 Component: xpressive
Version: Boost 1.35.0 Severity: Problem
Keywords: Cc:

Description

End of line matching inside a string is broken, simple example:

Subject: abc\ndef\nghi Regex: .+$

I'm looking for "abc". The following xpressive-based code has odd results:

string text(argv[1]); sregex rex = sregex::compile(text, regex_constants::not_dot_newline);

smatch match; string subject("abc\ndef\nghi"); if (regex_search(subject.begin(), subject.end(), match, rex, regex_constants::match_default)) {

std::cout << "Match at: " << match.position(0) << " length: " << match.length(0);

}

.+$: Match at: 8 length: 3 $: Match at: 4 length: 0 .$: Match at: 10 length: 1

These definitely aren't right, it appears that the only place where end-of-line is matching is at end-of-string. Things get even stranger if I try to use Windows or Mac style end-of-line styles. If I use boost::regex instead then I get these results:

.+$: Match at: 0 length: 3 $: Match at: 3 length: 0 .$: Match at: 2 length: 1

These are the results I'd expect. It appears in Xpressive that the check in assert_line_base::is_line_break is broken, the following line:

if(traits_cast<Traits>(state).isctype(ch, this->newline_))

checks the previous character to see if it's a line break. I believe this should check the current character:

if(traits_cast<Traits>(state).isctype(*state.cur_, this->newline_))

This then gets me sane results:

.+$: Match at: 0 length: 3 $: Match at: 3 length: 0 .$: Match at: 2 length: 1

[note: Eric says that this patch is probably not correct as it causes regression failures]

Attachments

Change History

comment:1 Changed 6 years ago by eric_niebler

  • Status changed from new to closed
  • Resolution set to fixed

(In [47899]) fixed buggy eol matching behavior (fixes #2157)

comment:2 Changed 6 years ago by eric_niebler

  • Status changed from closed to reopened
  • Resolution fixed deleted

The fix is not quite right ...

comment:3 Changed 6 years ago by eric_niebler

  • Status changed from reopened to closed
  • Resolution set to fixed

(In [47901]) ok, really fix end-of-line handling (fixes #2157)

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.