As of right now, invalid {} constructs are not handled consistently between BREs and EREs. Observe:
$ echo "a{1,2,3}b" | sed -r "s/{/_/" # Works! $ echo "a{1,2,3}b" | sed "s/\{/_/" # Throws an error - correct behavior $ echo "a{1,2,3}b" | sed -r "s/}/_/" # Works! $ echo "a{1,2,3}b" | sed "s/\}/_/" # Throws an error! - wrong behavior $ echo "a{1,2,3}b" | sed -r "s/{}/_/" # Works! $ echo "a{1,2,3}b" | sed "s/\{\}/_/" # Throws an error! - correct behavior
Where correct behavior/wrong behavior is based on:
- Strict interpretation of re_format(7)
- How modern GNU regex(3) operates, not counting some GNU-specific weirdness I found (such as a{,} being valid) that will be ignored for the time being.
- Which behavior seemed to be more reasonable in terms of 'this could go really badly if someone wrote these expecting valid repetitions'
While we're here, adjust tests to meet future expectations:
- { should never be interpreted literally in EREs, invalidating ERE expressions like {,2}, {,}, and {b} because they relied on the literal interpretation of { in EREs.
- Add a couple of cases to ensure that \{ and \} are handled similarly in BREs to { and } in EREs so that we're actually consistent going forward
PR: 166861