summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-16 09:59:05 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-16 09:59:05 -0500
commit2f3feff2f4a07142cad598e853a63ac11e33aad0 (patch)
tree3246a73484143c37254ad608c0fc7df8deeb78fa
parent298faea77aa1fee68084f30dc385b08bb103f3eb (diff)
Enforce character constraints on source filenames
-rw-r--r--src/compiler.sml14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/compiler.sml b/src/compiler.sml
index 9a25902a..67c94d91 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -794,7 +794,19 @@ val parse = {
val anyErrors = ref false
fun checkErrors () = anyErrors := (!anyErrors orelse ErrorMsg.anyErrors ())
- fun nameOf fname = capitalize (OS.Path.file fname)
+ fun nameOf fname =
+ let
+ val fname = OS.Path.file fname
+ val fst = if size fname = 0 then #"!" else String.sub (fname, 0)
+ in
+ if not (Char.isAlpha fst) then
+ ErrorMsg.error ("Filename doesn't start with letter: " ^ fname)
+ else if CharVector.exists (fn ch => not (Char.isAlphaNum ch) andalso ch <> #"_") fname then
+ ErrorMsg.error ("Filename contains a character that isn't alphanumeric or underscore: " ^ fname)
+ else
+ ();
+ capitalize fname
+ end
fun parseFfi fname =
let