expr(1) claims to be POSIX compliant but isn't

Originator:ohnobinki
Number:rdar://8319378 Date Originated:2010-08-17
Status:Closed Resolved:2012-07-26
Product:OS X Product Version:10.5.8
Classification: Reproducible:
 
Summary:

peter-krakers-mac-mini:unreal binki$ /bin/expr X--enable-permissions=0660 : '[^=]*\(.*\)'
=0660
peter-krakers-mac-mini:unreal binki$ /bin/expr X--enable-permissions=0660 : '[^=]*=\(.*\)'
660

According to the manpage expr(1):
     The expr utility conforms to IEEE Std 1003.2 (``POSIX.2'').

According to the POSIX manpage for expr(1p):
   Matching Expression
       The  ':'  matching  operator shall compare the string resulting from the evaluation of expr1 with the regular expression pattern resulting from the evaluation of expr2. Regular expression syntax shall be that defined in the Base Definitions
       volume of IEEE Std 1003.1-2001, Section 9.3, Basic Regular Expressions, except that all patterns are anchored to the beginning of the string (that is, only sequences starting at the first character of a string are  matched  by  the  regular
       expression)  and,  therefore,  it is unspecified whether '^' is a special character in that context. Usually, the matching operator shall return a string representing the number of characters matched ( '0' on failure). Alternatively, if the
       pattern contains at least one regular expression subexpression "[\(...\)]", the string corresponding to "\1" shall be returned.



Expected output from a more conformant expr:

ohnobinki@ohnopublishing ~/unreal.0 $ /bin/expr X--enable-permissions=0660 : '[^=]*=\(.*\)'
0660


It is quite obvious that the expression does _not_ ask for the `0' to be removed. In certain contexts, such as C code, leading zeroes are of great significance. For example, this causes problems when building unrealircd on Mac OSX: http://bugs.unrealircd.org/view.php?id=3189


----


Apple Developer Relations 26-Jul-2012 06:19 PM


We believe this issue has been addressed in OS X 10.8.


----

And I have just verified that this is fixed in OS X 10.9 userspace.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!