raco pkg: handle bad collection
strings
Also, add `setup/collection-name`, which provides functions for checking collection-name syntax. Closes PR 13886
This commit is contained in:
parent
a30d80a9c4
commit
95368d238e
|
@ -11,6 +11,7 @@
|
||||||
setup/dirs
|
setup/dirs
|
||||||
setup/getinfo
|
setup/getinfo
|
||||||
setup/main-collects
|
setup/main-collects
|
||||||
|
setup/collection-name
|
||||||
setup/path-to-relative
|
setup/path-to-relative
|
||||||
setup/xref scribble/xref
|
setup/xref scribble/xref
|
||||||
;; info -- no bindings from this are used
|
;; info -- no bindings from this are used
|
||||||
|
@ -1406,6 +1407,32 @@ compatibility.}
|
||||||
function).
|
function).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@; ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@section[#:tag "collection-names"]{API for Collection Names}
|
||||||
|
|
||||||
|
@defmodule[setup/collection-name]
|
||||||
|
|
||||||
|
@defproc[(collection-name? [v any/c]) boolean?]{
|
||||||
|
|
||||||
|
Returns @racket[#t] if @racket[v] is a string that is syntactically
|
||||||
|
valid as a collection name, which means that it is one or more
|
||||||
|
@litchar{/}-separated strings for which
|
||||||
|
@racket[collection-name-element?] returns true.}
|
||||||
|
|
||||||
|
|
||||||
|
@defproc[(collection-name-element? [v any/c]) boolean?]{
|
||||||
|
|
||||||
|
Returns @racket[#t] if @racket[v] is a string that is syntactically
|
||||||
|
valid as a top-level collection name or as a part of a collection
|
||||||
|
name, which means that it is non-empty and contains only ASCII
|
||||||
|
letters, ASCII digits, @litchar{-}, @litchar{+}, @litchar{_}, and
|
||||||
|
@litchar{%}, where a @litchar{%} is allowed only when followed by two
|
||||||
|
lowercase hexadecimal digits, and the digits must form a number that
|
||||||
|
is not the ASCII value of a letter, digit, @litchar{-}, @litchar{+},
|
||||||
|
or @litchar{_}.}
|
||||||
|
|
||||||
|
|
||||||
@; ------------------------------------------------------------------------
|
@; ------------------------------------------------------------------------
|
||||||
|
|
||||||
@section[#:tag "xref"]{API for Cross-References for Installed Manuals}
|
@section[#:tag "xref"]{API for Cross-References for Installed Manuals}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#lang racket/base
|
||||||
|
(require rackunit
|
||||||
|
setup/collection-name)
|
||||||
|
|
||||||
|
(check-equal? #t (collection-name-element? "racket"))
|
||||||
|
(check-equal? #t (collection-name-element? "racket%21"))
|
||||||
|
(check-equal? #f (collection-name-element? "racket.rkt"))
|
||||||
|
(check-equal? #f (collection-name-element? "racket!"))
|
||||||
|
(check-equal? #f (collection-name-element? "rac/ket"))
|
||||||
|
|
||||||
|
(check-equal? #t (collection-name? "racket"))
|
||||||
|
(check-equal? #t (collection-name? "rac/ket"))
|
||||||
|
(check-equal? #t (collection-name? "racket/%21"))
|
||||||
|
(check-equal? #f (collection-name? "racket.rkt"))
|
||||||
|
(check-equal? #f (collection-name? "racket!"))
|
||||||
|
(check-equal? #f (collection-name? "racket/"))
|
||||||
|
(check-equal? #f (collection-name? "/racket"))
|
|
@ -10,6 +10,7 @@
|
||||||
setup/pack
|
setup/pack
|
||||||
setup/unpack
|
setup/unpack
|
||||||
setup/dirs
|
setup/dirs
|
||||||
|
setup/collection-name
|
||||||
racket/port
|
racket/port
|
||||||
racket/list
|
racket/list
|
||||||
racket/function
|
racket/function
|
||||||
|
@ -1604,16 +1605,17 @@
|
||||||
(if (not i)
|
(if (not i)
|
||||||
pkg-name
|
pkg-name
|
||||||
(let ([s (i 'collection (lambda () 'use-pkg-name))])
|
(let ([s (i 'collection (lambda () 'use-pkg-name))])
|
||||||
(unless (or (string? s)
|
(unless (or (collection-name-element? s)
|
||||||
(eq? s 'multi)
|
(eq? s 'multi)
|
||||||
(eq? s 'use-pkg-name))
|
(eq? s 'use-pkg-name))
|
||||||
(log-error (format (~a "bad `collection' definition in \"info.rkt\n"
|
(log-error (format (~a "bad `collection' definition in \"info.rkt\";\n"
|
||||||
|
" definition will be ignored\n"
|
||||||
" path: ~a\n"
|
" path: ~a\n"
|
||||||
" found: ~e\n"
|
" found: ~e\n"
|
||||||
" expected: (or/c string? 'multi 'use-pkg-name)")
|
" expected: (or/c collection-name-element? 'multi 'use-pkg-name)")
|
||||||
(build-path dir "info.rkt")
|
(build-path dir "info.rkt")
|
||||||
s)))
|
s)))
|
||||||
(or (and (string? s)
|
(or (and (collection-name-element? s)
|
||||||
s)
|
s)
|
||||||
(and (eq? s 'use-pkg-name)
|
(and (eq? s 'use-pkg-name)
|
||||||
pkg-name)))))
|
pkg-name)))))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
Version 5.90.0.9
|
Version 5.90.0.9
|
||||||
Allow hash table chaperones and impersonators to Support efficient
|
Allow hash table chaperones and impersonators to Support efficient
|
||||||
hash-clear and hash-clear!
|
hash-clear and hash-clear!
|
||||||
|
setup/collection-name: added
|
||||||
|
|
||||||
Version 5.90.0.6
|
Version 5.90.0.6
|
||||||
Added path<?, symbol<?
|
Added path<?, symbol<?
|
||||||
|
|
14
racket/collects/setup/collection-name.rkt
Normal file
14
racket/collects/setup/collection-name.rkt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
#lang racket/base
|
||||||
|
|
||||||
|
(provide collection-name?
|
||||||
|
collection-name-element?)
|
||||||
|
|
||||||
|
(define (collection-name? name)
|
||||||
|
(and (string? name)
|
||||||
|
(andmap collection-name-element? (regexp-split #rx"/" name))))
|
||||||
|
|
||||||
|
(define (collection-name-element? name)
|
||||||
|
(and (string? name)
|
||||||
|
(regexp-match #rx"^[a-zA-z0-9+_%-]+$" name)
|
||||||
|
;; Using `module-path?' checks that "%" is used apprrpriately:
|
||||||
|
(module-path? name)))
|
|
@ -1,7 +1,8 @@
|
||||||
#lang racket/base
|
#lang racket/base
|
||||||
(require racket/file
|
(require racket/file
|
||||||
racket/path
|
racket/path
|
||||||
setup/dirs)
|
setup/dirs
|
||||||
|
setup/collection-name)
|
||||||
|
|
||||||
(provide links)
|
(provide links)
|
||||||
|
|
||||||
|
@ -20,8 +21,7 @@
|
||||||
#:with-path? [with-path? #f]
|
#:with-path? [with-path? #f]
|
||||||
. dirs)
|
. dirs)
|
||||||
(define (check-name name)
|
(define (check-name name)
|
||||||
(unless (and (regexp-match #rx"^[a-zA-z0-9+_%-]+$" name)
|
(unless (collection-name-element? name)
|
||||||
(module-path? name))
|
|
||||||
(error 'links "name is not valid as a top-level collection name: ~e"
|
(error 'links "name is not valid as a top-level collection name: ~e"
|
||||||
name)))
|
name)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user