1+ /*
2+ * Copyright 2025-Present, Redis Ltd. and Contributors All rights reserved. Licensed under the MIT
3+ * License.
4+ */
15package redis .clients .jedis ;
26
3- import java .io .Serializable ;
47import java .util .ArrayList ;
58import java .util .Arrays ;
69import java .util .Collections ;
2023 * @see ClientSetInfoConfig
2124 * @see <a href="https://redis.io/docs/latest/commands/client-setinfo/">CLIENT SETINFO</a>
2225 */
23- public final class DriverInfo implements Serializable {
24-
25- private static final long serialVersionUID = 1L ;
26-
27- /**
28- * Regex pattern for driver name validation. The name must start with a lowercase letter and
29- * contain only lowercase letters, digits, hyphens, and underscores. Dots are only allowed after
30- * digits (for Scala cross-version naming like akka-redis_2.13). Follows Maven artifactId naming
31- * conventions but also allows underscores and version-specific dots.
32- * @see <a href="https://maven.apache.org/guides/mini/guide-naming-conventions.html">Maven Naming
33- * Conventions</a>
34- */
35- private static final String DRIVER_NAME_PATTERN = "^[a-z][a-z0-9_-]*(?:[0-9]\\ .[0-9]+)?$" ;
26+ public final class DriverInfo {
3627
3728 /**
3829 * Set of brace characters that are not allowed in driver names or versions. These characters are
@@ -120,7 +111,7 @@ public String getName() {
120111 */
121112 public String getUpstreamDrivers () {
122113 if (upstreamDrivers .isEmpty ()) {
123- return null ;
114+ return "" ;
124115 }
125116 return String .join (";" , upstreamDrivers );
126117 }
@@ -196,8 +187,8 @@ public Builder addUpstreamDriver(String driverName, String driverVersion) {
196187 if (driverVersion == null ) {
197188 throw new JedisValidationException ("Driver version must not be null" );
198189 }
199- validateDriverName (driverName );
200- validateDriverVersion (driverVersion );
190+ validateDriverField (driverName , "Driver name" );
191+ validateDriverField (driverVersion , "Driver version" );
201192 String formattedDriverInfo = formatDriverInfo (driverName , driverVersion );
202193 this .upstreamDrivers .add (0 , formattedDriverInfo );
203194 return this ;
@@ -207,7 +198,7 @@ public Builder addUpstreamDriver(String driverName) {
207198 if (driverName == null ) {
208199 throw new JedisValidationException ("Driver name must not be null" );
209200 }
210- validateDriverName (driverName );
201+ validateDriverField (driverName , "Driver name" );
211202 this .upstreamDrivers .add (0 , driverName );
212203 return this ;
213204 }
@@ -222,48 +213,22 @@ public DriverInfo build() {
222213 }
223214
224215 /**
225- * Validates that the driver name follows Maven artifactId naming conventions: lowercase letters,
226- * digits, hyphens, and underscores only, starting with a lowercase letter. Dots are only allowed
227- * after digits (for Scala cross-version naming like akka-redis_2.13).
216+ * Validates that the value does not contain characters that would violate the format of the Redis
217+ * CLIENT LIST reply.
228218 * <p>
229- * Additionally validates Redis CLIENT LIST constraints: no spaces, newlines, non-printable
230- * characters, or braces.
231- * @param driverName the driver name to validate
232- * @throws JedisValidationException if the driver name does not follow the expected naming
233- * conventions
234- * @see <a href="https://maven.apache.org/guides/mini/guide-naming-conventions.html">Maven Naming
235- * Conventions</a>
236- * @see <a href="https://redis.io/docs/latest/commands/client-setinfo/">CLIENT SETINFO</a>
237- */
238- private static void validateDriverName (String driverName ) {
239- if (driverName .trim ().isEmpty ()) {
240- throw new JedisValidationException ("Driver name must not be empty" );
241- }
242-
243- validateNoInvalidCharacters (driverName , "Driver name" );
244-
245- if (!driverName .matches (DRIVER_NAME_PATTERN )) {
246- throw new JedisValidationException (
247- "Upstream driver name must follow Maven artifactId naming conventions: "
248- + "lowercase letters, digits, hyphens, and underscores only, starting with a lowercase letter "
249- + "(e.g., 'spring-data-redis', 'lettuce-core', 'akka-redis_2.13')" );
250- }
251- }
252-
253- /**
254- * Validates that the driver version does not contain characters that would violate the format of
255- * the Redis CLIENT LIST reply: no spaces, newlines, non-printable characters, or brace
256- * characters.
257- * @param driverVersion the driver version to validate
258- * @throws JedisValidationException if the driver version contains invalid characters
219+ * Only printable ASCII characters (0x21-0x7E, i.e., '!' to '~') are allowed, excluding braces.
220+ * @param value the value to validate
221+ * @param fieldName the name of the field for error messages (e.g., "Driver name", "Driver
222+ * version")
223+ * @throws JedisValidationException if the value is empty or contains invalid characters
259224 * @see <a href="https://redis.io/docs/latest/commands/client-setinfo/">CLIENT SETINFO</a>
260225 */
261- private static void validateDriverVersion (String driverVersion ) {
262- if (driverVersion .trim ().isEmpty ()) {
263- throw new JedisValidationException ("Driver version must not be empty" );
226+ private static void validateDriverField (String value , String fieldName ) {
227+ if (value .trim ().isEmpty ()) {
228+ throw new JedisValidationException (fieldName + " must not be empty" );
264229 }
265230
266- validateNoInvalidCharacters (driverVersion , "Driver version" );
231+ validateNoInvalidCharacters (value , fieldName );
267232 }
268233
269234 /**
0 commit comments