uuid: 'fat-uuid->string' preserves leading zeros.

Fixes <https://bugs.gnu.org/35582>.
Reported by sirgazil <sirgazil@zoho.com>.

Previously, leading zeros would be removed, leading to an "invalid"
UUID:

  (uuid->string (uuid "00CA-050E" 'fat32))
  ⇒ "CA-50E"
  (string->uuid "CA-50E" 'fat32)
  ⇒ #f

* gnu/system/uuid.scm (fat-uuid->string): Pad digits with zeros.
* tests/uuid.scm ("uuid, FAT32, leading zeros preserved"): New test.
This commit is contained in:
Ludovic Courtès 2019-05-07 10:50:28 +02:00
parent 08c06cd8ac
commit 6c5790a2fa
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 7 additions and 3 deletions

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2016, 2017, 2018 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Danny Milosavljevic <dannym@scratchpost.org> ;;; Copyright © 2017 Danny Milosavljevic <dannym@scratchpost.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
@ -175,7 +175,7 @@ (define (fat-uuid->string uuid)
"Convert FAT32/FAT16 UUID, a 4-byte bytevector, to its string representation." "Convert FAT32/FAT16 UUID, a 4-byte bytevector, to its string representation."
(let ((high (bytevector-uint-ref uuid 0 %fat-endianness 2)) (let ((high (bytevector-uint-ref uuid 0 %fat-endianness 2))
(low (bytevector-uint-ref uuid 2 %fat-endianness 2))) (low (bytevector-uint-ref uuid 2 %fat-endianness 2)))
(format #f "~:@(~x-~x~)" low high))) (format #f "~:@(~4,'0x-~4,'0x~)" low high)))
(define %fat-uuid-rx (define %fat-uuid-rx
(make-regexp "^([[:xdigit:]]{4})-([[:xdigit:]]{4})$")) (make-regexp "^([[:xdigit:]]{4})-([[:xdigit:]]{4})$"))

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2017, 2018 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2015, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -57,6 +57,10 @@ (define-module (test-uuid)
"1234-ABCD" "1234-ABCD"
(uuid->string (uuid "1234-abcd" 'fat32))) (uuid->string (uuid "1234-abcd" 'fat32)))
(test-equal "uuid, FAT32, leading zeros preserved"
"00CA-050E" ;<https://bugs.gnu.org/35582>
(uuid->string (uuid "00CA-050E" 'fat32)))
(test-assert "uuid, dynamic value" (test-assert "uuid, dynamic value"
(let* ((good "4dab5feb-d176-45de-b287-9b0a6e4c01cb") (let* ((good "4dab5feb-d176-45de-b287-9b0a6e4c01cb")
(bad (string-drop good 3))) (bad (string-drop good 3)))