Skip to content

Commit 2351f35

Browse files
committed
[Vertex AI] Add location checks for slashes and whitespace (#12849)
1 parent 3340c70 commit 2351f35

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public class VertexAI: NSObject {
2626
/// The default `VertexAI` instance.
2727
///
2828
/// - Parameter location: The region identifier, defaulting to `us-central1`; see [Vertex AI
29-
/// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions) for a
30-
/// list of supported regions.
29+
/// regions
30+
/// ](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
31+
/// for a list of supported regions.
3132
/// - Returns: An instance of `VertexAI`, configured with the default `FirebaseApp`.
3233
public static func vertexAI(location: String = "us-central1") -> VertexAI {
3334
guard let app = FirebaseApp.app() else {
@@ -41,8 +42,8 @@ public class VertexAI: NSObject {
4142
///
4243
/// - Parameters:
4344
/// - app: The custom `FirebaseApp` used for initialization.
44-
/// - location: The region identifier, defaulting to `us-central1`; see [Vertex AI
45-
/// regions](https://cloud.google.com/vertex-ai/docs/general/locations#vertex-ai-regions)
45+
/// - location: The region identifier, defaulting to `us-central1`; see [Vertex AI regions
46+
/// ](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
4647
/// for a list of supported regions.
4748
/// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`.
4849
public static func vertexAI(app: FirebaseApp, location: String = "us-central1") -> VertexAI {
@@ -117,11 +118,12 @@ public class VertexAI: NSObject {
117118
guard let projectID = app.options.projectID else {
118119
fatalError("The Firebase app named \"\(app.name)\" has no project ID in its configuration.")
119120
}
120-
guard !location.isEmpty else {
121+
guard !location.isEmpty && location
122+
.allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else {
121123
fatalError("""
122-
No location specified; see
123-
https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for a
124-
list of available regions.
124+
Invalid location "\(location)" specified; see \
125+
https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for \
126+
a list of available regions.
125127
""")
126128
}
127129

0 commit comments

Comments
 (0)