diff --git a/SOPT-iOS/Projects/Core/Sources/Extension/Foundation+/String+.swift b/SOPT-iOS/Projects/Core/Sources/Extension/Foundation+/String+.swift index 55bebb5b..197f9c34 100644 --- a/SOPT-iOS/Projects/Core/Sources/Extension/Foundation+/String+.swift +++ b/SOPT-iOS/Projects/Core/Sources/Extension/Foundation+/String+.swift @@ -75,3 +75,30 @@ public extension String { return map({String($0)}).last } } + +public extension String { + func isPercentEncoded() -> Bool { + guard let decodedString = self.removingPercentEncoding, + let decodedData = decodedString.data(using: .utf8) + else { return false } + + let encodedData = self.data(using: .utf8) + + return encodedData != decodedData + } + + func removePercentEncodingIfNeeded() -> String { + func removePercentEncodingRecursively(with string: String, attempts: Int) -> String { + guard attempts > 0 else { return string } + + let decodedString = string.removingPercentEncoding ?? string + return decodedString.isPercentEncoded() ? removePercentEncodingRecursively(with: decodedString, attempts: attempts - 1) : decodedString + } + + guard isPercentEncoded(), + let decodedString = self.removingPercentEncoding + else { return self } + + return removePercentEncodingRecursively(with: decodedString, attempts: 2) + } +} diff --git a/SOPT-iOS/Projects/Core/Sources/Utils/setImage.swift b/SOPT-iOS/Projects/Core/Sources/Utils/setImage.swift index 71976889..47666599 100644 --- a/SOPT-iOS/Projects/Core/Sources/Utils/setImage.swift +++ b/SOPT-iOS/Projects/Core/Sources/Utils/setImage.swift @@ -10,6 +10,14 @@ import Kingfisher public extension UIImageView { func setImage(with urlString: String, placeholder: UIImage? = nil, completion: ((UIImage?) -> Void)? = nil) { + guard let urlString = urlString + .removePercentEncodingIfNeeded() + .addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) + else { + print("URL 인코딩 실패") + return + } + let cache = ImageCache.default if urlString == "" { self.image = placeholder diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileCardView.swift b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileCardView.swift index 5d38933b..b487c352 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileCardView.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileCardView.swift @@ -30,6 +30,7 @@ public final class PokeProfileCardView: UIView, PokeCompatible { imageView.backgroundColor = DSKitAsset.Colors.gray700.color imageView.clipsToBounds = true imageView.contentMode = .scaleAspectFill + imageView.image = DSKitAsset.Assets.iconDefaultProfile.image return imageView }() diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileImageView.swift b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileImageView.swift index 53c89713..1570fd1d 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileImageView.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Sources/Components/PokeProfileImageView.swift @@ -29,6 +29,7 @@ public final class PokeProfileImageView: UIImageView { private func setUI() { self.backgroundColor = DSKitAsset.Colors.gray700.color + self.image = DSKitAsset.Assets.iconDefaultProfile.image self.clipsToBounds = true self.layer.borderWidth = 2 self.contentMode = .scaleAspectFill diff --git a/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMainScene/Views/ProfileCardGroupView.swift b/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMainScene/Views/ProfileCardGroupView.swift index 3179b84a..3419434e 100644 --- a/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMainScene/Views/ProfileCardGroupView.swift +++ b/SOPT-iOS/Projects/Features/PokeFeature/Sources/PokeMainScene/Views/ProfileCardGroupView.swift @@ -37,9 +37,11 @@ public final class ProfileCardGroupView: UIView, PokeCompatible { // MARK: - UI Components private let friendProfileImageView = UIImageView().then { + $0.image = DSKitAsset.Assets.iconDefaultProfile.image $0.layer.cornerRadius = 15 $0.backgroundColor = DSKitAsset.Colors.gray700.color $0.clipsToBounds = true + $0.contentMode = .scaleAspectFill } private let friendNameLabel = UILabel().then {