Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions iBox/Sources/AddBookmark/AddBookmarkViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,21 @@ final class AddBookmarkViewController: UIViewController {

@objc private func addButtonTapped() {
guard let name = addBookmarkView.nameTextView.text, !name.isEmpty,
let urlString = addBookmarkView.urlTextView.text, !urlString.isEmpty,
let encodedUrlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: encodedUrlString) else {
var urlString = addBookmarkView.urlTextView.text, !urlString.isEmpty else {
print("Invalid input")
return
}

let lowercasedUrlString = urlString.lowercased()
if !lowercasedUrlString.hasPrefix("https://") && !lowercasedUrlString.hasPrefix("http://") {
urlString = "https://" + urlString
}

guard let encodedUrlString = urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
let url = URL(string: encodedUrlString) else {
print("Invalid URL format")
return
}

let newBookmark = Bookmark(id: UUID(), name: name, url: url)

Expand Down