diff --git a/iBox/Sources/AddBookmark/AddBookmarkViewController.swift b/iBox/Sources/AddBookmark/AddBookmarkViewController.swift index e9fb193..363850a 100644 --- a/iBox/Sources/AddBookmark/AddBookmarkViewController.swift +++ b/iBox/Sources/AddBookmark/AddBookmarkViewController.swift @@ -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)