mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 00:53:21 +00:00 
			
		
		
		
	GUACAMOLE-760: Add validation and tests for the TimeZoneGuacamoleProperty
This commit is contained in:
		| @@ -20,7 +20,9 @@ | ||||
| package org.apache.guacamole.properties; | ||||
|  | ||||
| import java.util.TimeZone; | ||||
| import java.util.regex.Pattern; | ||||
| import org.apache.guacamole.GuacamoleException; | ||||
| import org.apache.guacamole.GuacamoleServerException; | ||||
|  | ||||
| /** | ||||
|  * A GuacamoleProperty whose value is a TimeZone. | ||||
| @@ -28,6 +30,12 @@ import org.apache.guacamole.GuacamoleException; | ||||
| public abstract class TimeZoneGuacamoleProperty | ||||
|         implements GuacamoleProperty<TimeZone> { | ||||
|      | ||||
|     /** | ||||
|      * A regex that matches valid variants of GMT timezones. | ||||
|      */ | ||||
|     public static final Pattern GMT_REGEX = | ||||
|             Pattern.compile("^GMT([+-](0|00)((:)?00)?)?$"); | ||||
|      | ||||
|     @Override | ||||
|     public TimeZone parseValue(String value) throws GuacamoleException { | ||||
|          | ||||
| @@ -36,7 +44,16 @@ public abstract class TimeZoneGuacamoleProperty | ||||
|             return null; | ||||
|          | ||||
|         // Attempt to return the TimeZone of the provided string value. | ||||
|         return TimeZone.getTimeZone(value); | ||||
|         TimeZone tz = TimeZone.getTimeZone(value); | ||||
|          | ||||
|         // If the input is not GMT, but the output is GMT, the TimeZone is not | ||||
|         // valid and we throw an exception. | ||||
|         if (!GMT_REGEX.matcher(value).matches() | ||||
|                 && GMT_REGEX.matcher(tz.getID()).matches()) | ||||
|             throw new GuacamoleServerException("Property \"" + getName() | ||||
|                 + "\" does not specify a valid time zone."); | ||||
|  | ||||
|         return tz; | ||||
|          | ||||
|     } | ||||
|      | ||||
|   | ||||
		Reference in New Issue
	
	Block a user