GNU bug report logs - #75151
[PATCH] import/utils: beautify-description: Validate argument

Previous Next

Package: guix-patches;

Reported by: Morgan Smith <Morgan.J.Smith <at> outlook.com>

Date: Fri, 27 Dec 2024 22:22:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75151 in the body.
You can then email your comments to 75151 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#75151; Package guix-patches. (Fri, 27 Dec 2024 22:22:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Morgan Smith <Morgan.J.Smith <at> outlook.com>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Fri, 27 Dec 2024 22:22:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Morgan Smith <Morgan.J.Smith <at> outlook.com>
To: guix-patches <at> gnu.org
Cc: Morgan Smith <Morgan.J.Smith <at> outlook.com>
Subject: [PATCH] import/utils: beautify-description: Validate argument
Date: Fri, 27 Dec 2024 17:18:38 -0500
* guix/import/utils.scm (beautify-description): Fix broken check for
non-strings.  Add a check for empty strings.
* tests/import-utils.scm: Add two tests.

Change-Id: Idf86df02aeb850fcc8808b7c9251082c1f816656
---

Hello!

I was trying to run "guix import hackage orgstat" to no avail.  It turns out it
was because 'beautify-description' errors when given the empty string.  It
already had a check for arguments that where not a string but that check was
actually broken.  So I fixed the existing check and added a new one for an
empty string.

 guix/import/utils.scm  | 160 +++++++++++++++++++++--------------------
 tests/import-utils.scm |  10 +++
 2 files changed, 91 insertions(+), 79 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index e45c8dfb20..bb268ebe4b 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -328,85 +328,87 @@ (define* (beautify-description description #:optional (length 80))
   "Improve the package DESCRIPTION by turning a beginning sentence fragment into
 a proper sentence and by using two spaces between sentences, and wrap lines at
 LENGTH characters."
-  (unless (string? description)
-    (G_ "This package lacks a description.  Run \
-\"info '(guix) Synopses and Descriptions'\" for more information."))
-
-  (let* ((fix-word
-          (lambda (word)
-            (fold (lambda (proc acc) (proc acc)) word
-                  (list
-                   ;; Remove wrapping in single quotes, common in R packages.
-                   (cut string-trim-both <> #\')
-                   ;; Escape single @ to prevent it from being understood as
-                   ;; invalid Texinfo syntax.
-                   (cut regexp-substitute/global #f "@" <> 'pre "@@" 'post)
-                   ;; Wrap camelCase or PascalCase words or text followed
-                   ;; immediately by "()" in @code{...}.
-                   (lambda (word)
-                     (let ((pattern
-                            (make-regexp
-                             "([A-Z][a-z]+[A-Z]|[a-z]+[A-Z]|.+\\(\\))")))
-                       (match (list-matches pattern word)
-                         (() word)
-                         ((m . rest)
-                          ;; Do not include leading or trailing punctuation,
-                          ;; unless its "()".
-                          (let* ((last-text (if (string-suffix? "()" (match:substring m 1))
-                                                (string-length (match:substring m 1))
-                                                (or (and=> (string-skip-right word char-set:punctuation) 1+)
-                                                    (string-length word))))
-                                 (inner (substring word (match:start m) last-text))
-                                 (pre (string-take word (match:start m)))
-                                 (post (substring word last-text (string-length word))))
-                            (string-append pre "@code{" inner "}" post))))))))))
-         (words
-          (string-tokenize (string-trim-both description)
-                           (char-set-complement
-                            (char-set #\space #\newline))))
-         (new-words
-          (match words
-            (((and (or "A" "Classes" "Functions" "Methods" "Tools")
-                   first) . rest)
-             (cons* "This" "package" "provides"
-                    (string-downcase first) rest))
-            (((and (or "Contains"
-                       "Creates"
-                       "Performs"
-                       "Provides"
-                       "Produces"
-                       "Implements"
-                       "Infers") first) . rest)
-             (cons* "This" "package"
-                    (string-downcase first) rest))
-            (_ words)))
-         (new-words
-           (match new-words
-             ((rest ... last)
-              (reverse (cons (if (or (string-suffix? "." last)
-                                     (string-suffix? "!" last)
-                                     (string-suffix? "?" last))
-                               last
-                               (string-append last "."))
-                             (reverse rest))))))
-         (cleaned
-          (string-join (map fix-word new-words))))
-    ;; Use double spacing between sentences
-    (fill-paragraph (regexp-substitute/global #f "\\. \\b"
-                                              cleaned 'pre
-                                              (lambda (m)
-                                                (let ((pre (match:prefix m))
-                                                      (abbrevs '("Dr" "Mr" "Mrs"
-                                                                 "Ms" "Prof" "vs"
-                                                                 "e.g")))
-                                                  (if (and (> (string-length pre) 0)
-                                                           (or (any (cut string-suffix? <> pre) abbrevs)
-                                                               (char-upper-case?
-                                                                (string-ref pre (1- (string-length pre))))))
-                                                      ". "
-                                                      ".  ")))
-                                              'post)
-                    length)))
+  (if (or (not (string? description)) (string=? (string-trim-both description) ""))
+      (G_ "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information.")
+
+      (let* ((fix-word
+              (lambda (word)
+                (fold (lambda (proc acc) (proc acc)) word
+                      (list
+                       ;; Remove wrapping in single quotes, common in R packages.
+                       (cut string-trim-both <> #\')
+                       ;; Escape single @ to prevent it from being understood as
+                       ;; invalid Texinfo syntax.
+                       (cut regexp-substitute/global #f "@" <> 'pre "@@" 'post)
+                       ;; Wrap camelCase or PascalCase words or text followed
+                       ;; immediately by "()" in @code{...}.
+                       (lambda (word)
+                         (let ((pattern
+                                (make-regexp
+                                 "([A-Z][a-z]+[A-Z]|[a-z]+[A-Z]|.+\\(\\))")))
+                           (match (list-matches pattern word)
+                             (() word)
+                             ((m . rest)
+                              ;; Do not include leading or trailing punctuation,
+                              ;; unless its "()".
+                              (let* ((last-text
+                                      (if (string-suffix? "()" (match:substring m 1))
+                                          (string-length (match:substring m 1))
+                                          (or (and=> (string-skip-right word char-set:punctuation) 1+)
+                                              (string-length word))))
+                                     (inner (substring word (match:start m) last-text))
+                                     (pre (string-take word (match:start m)))
+                                     (post (substring word last-text (string-length word))))
+                                (string-append pre "@code{" inner "}" post))))))))))
+             (words
+              (string-tokenize (string-trim-both description)
+                               (char-set-complement
+                                (char-set #\space #\newline))))
+             (new-words
+              (match words
+                (((and (or "A" "Classes" "Functions" "Methods" "Tools")
+                       first) . rest)
+                 (cons* "This" "package" "provides"
+                        (string-downcase first) rest))
+                (((and (or "Contains"
+                           "Creates"
+                           "Performs"
+                           "Provides"
+                           "Produces"
+                           "Implements"
+                           "Infers") first) . rest)
+                 (cons* "This" "package"
+                        (string-downcase first) rest))
+                (_ words)))
+             (new-words
+              (match new-words
+                ((rest ... last)
+                 (reverse (cons (if (or (string-suffix? "." last)
+                                        (string-suffix? "!" last)
+                                        (string-suffix? "?" last))
+                                    last
+                                    (string-append last "."))
+                                (reverse rest))))))
+             (cleaned
+              (string-join (map fix-word new-words))))
+        ;; Use double spacing between sentences
+        (fill-paragraph
+         (regexp-substitute/global #f "\\. \\b"
+                                   cleaned 'pre
+                                   (lambda (m)
+                                     (let ((pre (match:prefix m))
+                                           (abbrevs '("Dr" "Mr" "Mrs"
+                                                      "Ms" "Prof" "vs"
+                                                      "e.g")))
+                                       (if (and (> (string-length pre) 0)
+                                                (or (any (cut string-suffix? <> pre) abbrevs)
+                                                    (char-upper-case?
+                                                     (string-ref pre (1- (string-length pre))))))
+                                           ". "
+                                           ".  ")))
+                                   'post)
+         length))))
 
 (define (beautify-synopsis synopsis)
   "Improve the package SYNOPSIS."
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 607349203c..27bd87940a 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -31,6 +31,16 @@ (define-module (test-import-utils)
 
 (test-begin "import-utils")
 
+(test-equal "beautify-description: empty string"
+  "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."
+  (beautify-description ""))
+
+(test-equal "beautify-description: not a string"
+  "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."
+  (beautify-description '()))
+
 (test-equal "beautify-description: use double spacing"
   "\
 Trust me Mr. Hendrix, M. Night Shyamalan et al.  \

base-commit: 3a8c20408f0078a580d27f74bc69b5a1069a003b
--
2.47.1





Information forwarded to guix-patches <at> gnu.org:
bug#75151; Package guix-patches. (Mon, 07 Apr 2025 20:55:03 GMT) Full text and rfc822 format available.

Message #8 received at 75151 <at> debbugs.gnu.org (full text, mbox):

From: Morgan Smith <Morgan.J.Smith <at> outlook.com>
To: 75151 <at> debbugs.gnu.org
Cc: Morgan Smith <Morgan.J.Smith <at> outlook.com>
Subject: [PATCH v2] import/utils: beautify-description: Validate argument
Date: Mon,  7 Apr 2025 16:53:52 -0400
* guix/import/utils.scm (beautify-description): Fix broken check for
non-strings.  Add a check for empty strings.
* tests/import-utils.scm: Add two tests.

Change-Id: Idf86df02aeb850fcc8808b7c9251082c1f816656
---

Resending after rebasing this.

 guix/import/utils.scm  |  8 ++++----
 tests/import-utils.scm | 10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index 38c986b4d5..0ef84c9cdf 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -331,9 +331,9 @@ (define* (beautify-description description #:optional (length 80))
   "Improve the package DESCRIPTION by turning a beginning sentence fragment into
 a proper sentence and by using two spaces between sentences, and wrap lines at
 LENGTH characters."
-  (unless (string? description)
-    (G_ "This package lacks a description.  Run \
-\"info '(guix) Synopses and Descriptions'\" for more information."))
+  (if (or (not (string? description)) (string=? (string-trim-both description) ""))
+      (G_ "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information.")
 
   (let* ((fix-word
           (lambda (word)
@@ -410,7 +410,7 @@ (define* (beautify-description description #:optional (length 80))
                                                       ". "
                                                       ".  ")))
                                               'post)
-                    length)))
+                    length))))
 
 (define (beautify-synopsis synopsis)
   "Improve the package SYNOPSIS."
diff --git a/tests/import-utils.scm b/tests/import-utils.scm
index 221866e871..273f18254e 100644
--- a/tests/import-utils.scm
+++ b/tests/import-utils.scm
@@ -31,6 +31,16 @@ (define-module (test-import-utils)
 
 (test-begin "import-utils")
 
+(test-equal "beautify-description: empty string"
+  "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."
+  (beautify-description ""))
+
+(test-equal "beautify-description: not a string"
+  "This package lacks a description.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."
+  (beautify-description '()))
+
 (test-equal "beautify-description: use double spacing"
   "\
 Trust me Mr. Hendrix, M. Night Shyamalan et al.  \

base-commit: 666a6cfd88b3e5106a9180e06ea128db8084be0e
-- 
2.49.0





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Tue, 15 Apr 2025 08:25:06 GMT) Full text and rfc822 format available.

Notification sent to Morgan Smith <Morgan.J.Smith <at> outlook.com>:
bug acknowledged by developer. (Tue, 15 Apr 2025 08:25:06 GMT) Full text and rfc822 format available.

Message #13 received at 75151-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Morgan Smith <Morgan.J.Smith <at> outlook.com>
Cc: 75151-done <at> debbugs.gnu.org
Subject: Re: bug#75151: [PATCH] import/utils: beautify-description: Validate
 argument
Date: Tue, 15 Apr 2025 10:20:05 +0200
Morgan Smith <Morgan.J.Smith <at> outlook.com> writes:

> * guix/import/utils.scm (beautify-description): Fix broken check for
> non-strings.  Add a check for empty strings.
> * tests/import-utils.scm: Add two tests.
>
> Change-Id: Idf86df02aeb850fcc8808b7c9251082c1f816656

Applied, thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 13 May 2025 11:24:14 GMT) Full text and rfc822 format available.

This bug report was last modified 37 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.