From 3febabb7a728d5331e7a11e60025a5c746a1ee6c Mon Sep 17 00:00:00 2001 From: jonnwon Date: Wed, 17 Apr 2024 22:02:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=EA=B0=80=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=ED=95=9C=20URL=EC=97=90=20https://=EA=B0=80?= =?UTF-8?q?=20=EC=97=86=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=B6=94=EA=B0=80=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https:// 와 http:// 가 둘 다 없는 경우 https:// 를 추가 --- .../AddBookmark/AddBookmarkViewController.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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)