~julienxx/castor

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] Validate URL before adding to bookmarks

Details
Message ID
<20200526221413.16011-1-alex@alexwennerberg.com>
DKIM signature
fail
Download raw message
Patch: +12 -1 DKIM signature: fail
Fixes issue #20 (https://todo.sr.ht/~julienxx/Castor/20)

Throws an error dialog if URL is invalid before adding to bookmarks
---
 src/bookmarks.rs | 8 ++++++++
 src/main.rs      | 5 ++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/bookmarks.rs b/src/bookmarks.rs
index 3a5b8ea..6ae6a96 100644
--- a/src/bookmarks.rs
+++ b/src/bookmarks.rs
@@ -4,6 +4,14 @@ use std::fs;
use std::fs::File;
use std::fs::OpenOptions;
use std::io::{Read, Write};
use url::Url;

pub fn is_valid(url: &str) -> bool {
    match Url::parse(&url) {
        Ok(_) => true,
        _ => false,
    }
}

pub fn add(url: &str) {
    let mut file = bookmarks_file();
diff --git a/src/main.rs b/src/main.rs
index 240a3d6..4fbff8f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -161,10 +161,13 @@ fn add_bookmark(gui: &Arc<Gui>) {
    let current_url = url_bar.get_text();

    if let Some(url) = current_url {
        if url != "" {
        if bookmarks::is_valid(&url) {
            bookmarks::add(&url);
            dialog::info(&gui, "Bookmark added.");
        }
        else {
            dialog::error(&gui, "Invalid bookmark URL.");
        }
    }
}

-- 
2.20.1
Details
Message ID
<b699075b-5dba-f606-6d9e-94d0028b689d@typed-hole.org>
In-Reply-To
<20200526221413.16011-1-alex@alexwennerberg.com> (view parent)
DKIM signature
pass
Download raw message
Thanks for the patch!
Review patch Export thread (mbox)