diff options
author | Teddy Wing | 2018-04-11 02:15:26 +0200 |
---|---|---|
committer | Teddy Wing | 2018-04-11 02:15:26 +0200 |
commit | 348f1a987e248bb83d9c4c188333b67a2b3470cc (patch) | |
tree | 8f9d9a123c63fd1b3f213c2985235a74b2954fbb | |
parent | ebc1fdb1e763895b17801983b395ec2181548646 (diff) | |
download | w3m-session-backup-348f1a987e248bb83d9c4c188333b67a2b3470cc.tar.bz2 |
Wrap page title and URL in single quotes with escape
Ensure that special characters don't cause the YAML to be invalid by
wrapping the URL and page title in quotes to force them to be strings.
Escape any literal single quotes in the page title by doubling them.
Didn't escape single quotes in the URL because I'm assuming any present
will be URL encoded.
-rw-r--r-- | w3m-session-backup.el | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/w3m-session-backup.el b/w3m-session-backup.el index ca7192f..47710d5 100644 --- a/w3m-session-backup.el +++ b/w3m-session-backup.el @@ -27,6 +27,15 @@ ;; Format some YAML text to write to the file ;; Configurable dynamic filename based on date-time +(defun yml-escape (str) + "YAML escape single quotes by doubling them." + (replace-regexp-in-string + (regexp-quote "'") + "''" + str + 'fixedcase + 'literal)) + (defun save-backup () "TODO" (with-temp-file "~/tmp-w3m-session.yml" @@ -34,9 +43,9 @@ (string-join (mapcar (lambda (page) - (format "- page_title: %s - url: %s" - (first (last page)) + (format "- page_title: '%s' + url: '%s'" + (yml-escape (first (last page))) (first page))) (my-w3m-session-backup)) "\n")))) |