Bug 247931 - sed "y" command bracket balancing check
Summary: sed "y" command bracket balancing check
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Yuri Pankov
URL: https://reviews.freebsd.org/D25640
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-12 12:09 UTC by Quentin L'Hours
Modified: 2020-07-26 09:16 UTC (History)
2 users (show)

See Also:
antoine: exp-run+


Attachments
patch for exp-run (2.14 KB, patch)
2020-07-14 16:32 UTC, Yuri Pankov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Quentin L'Hours 2020-07-12 12:09:31 UTC
When using the "y" command, it seems like square bracket balancing is required. Square brackets should instead be treated like any other character in the "y" cmd context, as they are already at the time of doing the actual character replacement:

sh$ echo | sed 'y/[/x/'
sed: 1: "y/[/x/": unbalanced brackets ([])
sh$ echo | sed 'y/[]/xy/'
sed: 1: "y/[]/xy/": unbalanced brackets ([])
sh$ echo | sed 'y/[a]/xyz/'

sh$ echo '][a' | sed 'y/[a]/xyz/'
zxy
Comment 1 Yuri Pankov freebsd_committer 2020-07-13 03:43:53 UTC
(In reply to Quentin L'Hours from comment #0)
Could you please check if the patch from review fixes the issue for you?
Comment 2 Quentin L'Hours 2020-07-13 20:48:38 UTC
(In reply to Yuri Pankov from comment #1)
Yep works perfectly with this patch, thanks!
Comment 3 Yuri Pankov freebsd_committer 2020-07-14 16:32:38 UTC
Created attachment 216441 [details]
patch for exp-run
Comment 4 Yuri Pankov freebsd_committer 2020-07-14 16:33:45 UTC
Asking for exp-run on this change as sed has quite a history of backouts as breaking the ports.
Comment 5 Antoine Brodin freebsd_committer 2020-07-24 21:10:29 UTC
Exp-run looks fine
Comment 6 commit-hook freebsd_committer 2020-07-26 09:16:05 UTC
A commit references this bug:

Author: yuripv
Date: Sun Jul 26 09:15:05 UTC 2020
New revision: 363543
URL: https://svnweb.freebsd.org/changeset/base/363543

Log:
  sed: treat '[' as ordinary character in 'y' command

  'y' does not handle bracket expressions, treat '[' as ordinary character
  and do not apply bracket expression checks (GNU sed agrees).

  PR:		247931
  Reviewed by:	pfg, kevans
  Tested by:	antoine (exp-run), Quentin L'Hours <lhoursquentin@gmail.com>
  Differential Revision:	https://reviews.freebsd.org/D25640

Changes:
  head/usr.bin/sed/compile.c
  head/usr.bin/sed/tests/sed2_test.sh