guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/02: installer: Validate hostname while entering it; again.


From: Danny Milosavljevic
Subject: 02/02: installer: Validate hostname while entering it; again.
Date: Fri, 7 Jul 2017 16:05:40 -0400 (EDT)

dannym pushed a commit to branch wip-installer-2
in repository guix.

commit f47c540686263091c04f91b9ab5e371d65a67e26
Author: Danny Milosavljevic <address@hidden>
Date:   Fri Jul 7 22:04:35 2017 +0200

    installer: Validate hostname while entering it; again.
    
    * gnu/system/installer/hostname.scm (validator): New variable.
    (my-fields): Add it here.
---
 gnu/system/installer/hostname.scm | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/gnu/system/installer/hostname.scm 
b/gnu/system/installer/hostname.scm
index 57045ca..6372fe7 100644
--- a/gnu/system/installer/hostname.scm
+++ b/gnu/system/installer/hostname.scm
@@ -34,7 +34,12 @@
 
 (define max-length ((const 63)))
 
-(define my-fields `((name   ,(M_ "Host Name") ,max-length)))
+(define validator
+  (let ((regexp (make-regexp "^[A-Za-z0-9][-A-Za-z0-9]{0,62}$")))
+    (lambda (text)
+      (regexp-exec regexp text))))
+
+(define my-fields `((name   ,(M_ "Host Name") ,max-length ,validator)))
 
 (define (valid-hostname? name)
   "Return #t iff NAME is a valid hostname as defined by RFC 1034"
@@ -83,24 +88,6 @@
      'cancelled)
     (_ 'ignored))))
 
-#|     ;; Do not allow more than 63 characters
-     ((and (char? ch)
-           (char-set-contains? char-set:printing ch)
-           (>= (field-cursor-position (get-current-field form)) max-length)))
-
-     ;; The first character may not be  a hyphen
-     ((and (char? ch)
-           (eq? ch #\-)
-           (zero? (field-cursor-position (get-current-field form)))))
-
-     ;; Subsequent characters must be [-A-Za-z0-9]
-     ((and (char? ch)
-           (char-set-contains? char-set:printing ch)
-           (not (char-set-contains?
-                 (char-set-adjoin char-set:letter+digit #\-) ch))
-           (positive? (field-cursor-position (get-current-field form)))))
-|#
-
 (define my-buttons `((cancel ,(M_ "Cancel") #f)))
 
 (define (host-name-init p)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]