[M3devel] Pathname.Legal

Neels Janosch Hofmeyr neels at elego.de
Sun Oct 14 00:24:48 CEST 2007


Hello all,

I encountered the problem that, in my cm3 compile,
FS.GetAbsolutePathname cannot handle special characters in file names.
As soon as a file contains a special character (ä, ß, ø, ...), a
Pathname.Invalid exception is raised.

This happens because PathnamePosix.m3 has a list of legal characters:

  CONST Legal = SET OF CHAR {'\001' .. '\177'} - SET OF CHAR {DirSepChar};

which is enforced in Pathname.Compose and Pathname.ParsePosixPathname.

Pathname.Legal contains the complete ASCII list -- but no more than
that. This means that characters like ä are considered illegal characters.

I reversed the Legal list to an Illegal list like this:

  CONST Illegal = SET OF CHAR {DirSepChar};

and also reversed the IF logic, replacing Legal with Illegal. This way
all characters are allowed, except the DirSepChar. And voila, it works.
PathnamePosix.m3 accepts weird filenames.

So, should this fix be applied to cm3?

Regards,
Neels


cm3/m3-libs/libm3/src/os/POSIX/PathnamePosix.m3:
@@ -13,7 +13,7 @@
   DirSepChar = '/'; ExtSepChar = '.';
   DirSepText = "/"; ExtSepText = ".";
 
-CONST Legal = SET OF CHAR {'\001' .. '\177'} - SET OF CHAR {DirSepChar};
+CONST Illegal = SET OF CHAR {DirSepChar};
 
 PROCEDURE Valid(pn: T): BOOLEAN =
   PROCEDURE Ignore(<* UNUSED *> start, end: CARDINAL) = BEGIN END Ignore;
@@ -51,7 +51,7 @@
       WITH arc = a.get(i) DO
        IF arc = NIL THEN RAISE Invalid END;
        FOR i := 0 TO Text.Length(arc) - 1 DO
-         IF NOT Text.GetChar(arc, i) IN Legal THEN RAISE Invalid END
+         IF Text.GetChar(arc, i) IN Illegal THEN RAISE Invalid END
        END;
        t := t & arc
       END;
@@ -159,7 +159,7 @@
           IF c = DirSepChar THEN
             visit(s, e);
             s := e + 1
-          ELSIF NOT c IN Legal THEN
+          ELSIF c IN Illegal THEN
             RAISE Invalid
           END
         END;

-- 
Neels Janosch Hofmeyr
Software Developer

neels at elego.de
Public Key: http://binarchy.net/neels/neels.hofmeyr.public.key.asc

elego Software Solutions GmbH           http://www.elegosoft.com
Gustav-Meyer-Allee 25, Gebäude 12       HRB 77719
13355 Berlin, Germany                   Amtsgericht Charlottenburg
Tel.: +49 30 23 45 86 96                Sitz der Gesellschaft: Berlin
Fax:  +49 30 23 45 86 95                Geschäftsführer: Olaf Wagner


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20071014/b28541b6/attachment-0001.sig>


More information about the M3devel mailing list