[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/11: packages: Optionally validate Texinfo markup at expansion time.
From: |
guix-commits |
Subject: |
05/11: packages: Optionally validate Texinfo markup at expansion time. |
Date: |
Thu, 28 Oct 2021 15:43:15 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit e171182a20962c4119e12439b92bbbfd59b1495e
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Oct 18 17:49:55 2021 +0200
packages: Optionally validate Texinfo markup at expansion time.
* guix/packages.scm (validate-texinfo): New macro.
(<package>)[synopsis, description]: Add 'sanitize' property.
---
guix/packages.scm | 52 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/guix/packages.scm b/guix/packages.scm
index 780c6dd..4b6098b 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -49,6 +49,7 @@
#:use-module (srfi srfi-35)
#:use-module (rnrs bytevectors)
#:use-module (web uri)
+ #:autoload (texinfo) (texi-fragment->stexi)
#:re-export (%current-system
%current-target-system
search-path-specification) ;for convenience
@@ -438,6 +439,49 @@ lexical scope of its body."
(lambda (s) #,location)))
body ...))))))
+(define-syntax validate-texinfo
+ (let ((validate? (getenv "GUIX_UNINSTALLED")))
+ (define ensure-thread-safe-texinfo-parser!
+ ;; Work around <https://issues.guix.gnu.org/51264> for Guile <= 3.0.7.
+ (let ((patched? (or (> (string->number (major-version)) 3)
+ (> (string->number (minor-version)) 0)
+ (> (string->number (micro-version)) 7)))
+ (next-token-of/thread-safe
+ (lambda (pred port)
+ (let loop ((chars '()))
+ (match (read-char port)
+ ((? eof-object?)
+ (list->string (reverse! chars)))
+ (chr
+ (let ((chr* (pred chr)))
+ (if chr*
+ (loop (cons chr* chars))
+ (begin
+ (unread-char chr port)
+ (list->string (reverse! chars)))))))))))
+ (lambda ()
+ (unless patched?
+ (set! (@@ (texinfo) next-token-of) next-token-of/thread-safe)
+ (set! patched? #t)))))
+
+ (lambda (s)
+ "Raise a syntax error when passed a literal string that is not valid
+Texinfo. Otherwise, return the string."
+ (syntax-case s ()
+ ((_ str)
+ (string? (syntax->datum #'str))
+ (if validate?
+ (catch 'parser-error
+ (lambda ()
+ (ensure-thread-safe-texinfo-parser!)
+ (texi-fragment->stexi (syntax->datum #'str))
+ #'str)
+ (lambda _
+ (syntax-violation 'package "invalid Texinfo markup" #'str)))
+ #'str))
+ ((_ obj)
+ #'obj)))))
+
;; A package.
(define-record-type* <package>
package make-package
@@ -472,9 +516,11 @@ lexical scope of its body."
(replacement package-replacement ; package | #f
(default #f) (thunked) (innate))
- (synopsis package-synopsis) ; one-line description
- (description package-description) ; one or two paragraphs
- (license package-license) ; <license> instance or list
+ (synopsis package-synopsis
+ (sanitize validate-texinfo)) ; one-line description
+ (description package-description
+ (sanitize validate-texinfo)) ; one or two paragraphs
+ (license package-license) ; <license> instance or list
(home-page package-home-page)
(supported-systems package-supported-systems ; list of strings
(default %supported-systems))
- branch master updated (3fb1928 -> 7dbd533), guix-commits, 2021/10/28
- 02/11: doc: Allow offloading of the expensive derivations., guix-commits, 2021/10/28
- 01/11: import: cran: Use the standard diagnostic procedures., guix-commits, 2021/10/28
- 03/11: store: 'map/accumulate-builds' handler checks the store received., guix-commits, 2021/10/28
- 04/11: ui: Gracefully handle invalid Texinfo markup in package blurbs., guix-commits, 2021/10/28
- 06/11: gnu: waypipe: Simplify 'fix-sleep-path phase., guix-commits, 2021/10/28
- 08/11: gnu: Add cln., guix-commits, 2021/10/28
- 05/11: packages: Optionally validate Texinfo markup at expansion time.,
guix-commits <=
- 07/11: gnu: waypipe: Update to 0.8.1, guix-commits, 2021/10/28
- 09/11: gnu: Add ginac., guix-commits, 2021/10/28
- 11/11: gnu: python-slugify: Honor #:tests?., guix-commits, 2021/10/28
- 10/11: gnu: python-slugify: Update to 5.0.2., guix-commits, 2021/10/28