diff --git a/collects/mred/private/snipfile.ss b/collects/mred/private/snipfile.ss index ed990c49..db4e61ae 100644 --- a/collects/mred/private/snipfile.ss +++ b/collects/mred/private/snipfile.ss @@ -15,18 +15,39 @@ ;; snip-class% and editor-data-class% loaders + (define (ok-string-element? m) + (and (string? m) + (regexp-match? #rx"^[-a-zA-Z0-9_. ]+$" m) + (not (string=? m "..")) + (not (string=? m ".")))) + + (define (ok-lib-path? m) + (and (pair? m) + (eq? 'lib (car m)) + (pair? (cdr m)) + (list? m) + (andmap ok-string-element? (cdr m)))) + (let ([load-one (lambda (str id %) - (let ([m (with-handlers ([void (lambda (x) #f)]) + (let ([m (with-handlers ([exn:fail:read? (lambda (x) #f)]) (and (regexp-match #rx"^[(].*[)]$" str) - (read (open-input-string str))))]) - (if (and (list? m) - (eq? 'lib (car m)) - (andmap string? (cdr m))) - (let ([result (dynamic-require m id)]) - (if (is-a? result %) - result - (error 'load-class "not a ~a% instance" id))) + (let* ([p (open-input-string str)] + [m (read p)]) + (and (eof-object? (read p)) + m))))]) + (if (or (ok-lib-path? m) + (and (list? m) + (= (length m) 2) + (ok-lib-path? (car m) + (ok-lib-path? (cadr m))))) + (let ([m (if (ok-lib-path? m) + m + (car m))]) + (let ([result (dynamic-require m id)]) + (if (is-a? result %) + result + (error 'load-class "not a ~a% instance" id)))) #f)))]) ;; install the getters: (wx:set-snip-class-getter @@ -233,7 +254,7 @@ (let ([p (open-input-file filename)]) (port-count-lines! p) (let ([p (cond - [(regexp-match-peek #rx#"^WXME01[0-9][0-9] ## " p) + [(regexp-match-peek #rx#"^(?:#reader(lib\"wxme[.]ss\"\"mred\"))?WXME01[0-9][0-9] ## " p) (let ([t (make-object text%)]) (send t insert-port p 'standard) (close-input-port p)