File tree Expand file tree Collapse file tree
main/java/pl/edu/icm/unity/engine/api/utils
test/java/pl/edu/icm/unity/engine/api/utils
vaadin-endpoint-common/src/main/java/io/imunity/vaadin/endpoint/common/plugins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66package pl .edu .icm .unity .engine .api .utils ;
77
8+ import java .net .URLDecoder ;
9+ import java .net .URLEncoder ;
10+ import java .nio .charset .StandardCharsets ;
811import java .util .Base64 ;
912import java .util .Set ;
1013
@@ -21,7 +24,7 @@ public static String encode(String name)
2124 return Base64 .getUrlEncoder ()
2225 .encodeToString (name .getBytes ()) + ENCODED_NAME_SUFFIX ;
2326 }
24- return name ;
27+ return URLEncoder . encode ( name , StandardCharsets . UTF_8 ) ;
2528 }
2629
2730 public static String decode (String name )
@@ -31,6 +34,6 @@ public static String decode(String name)
3134 return new String (Base64 .getUrlDecoder ()
3235 .decode (name .substring (0 , name .length () - ENCODED_NAME_SUFFIX .length ())));
3336 }
34- return name ;
37+ return URLDecoder . decode ( name , StandardCharsets . UTF_8 ) ;
3538 }
3639}
Original file line number Diff line number Diff line change 1414public class NameToURLEncoderTest
1515{
1616 @ Test
17- public void shouldNotEncodeSafeName ()
17+ public void shouldNotEncodeToBase64SafeName ()
1818 {
1919 assertThat (NameToURLEncoder .encode ("name" )).isEqualTo ("name" );
2020 }
@@ -38,4 +38,16 @@ public void shouldDecodeUnsafeName()
3838 assertThat (NameToURLEncoder .decode (new String (Base64 .getUrlEncoder ()
3939 .encode ("/name" .getBytes ())) + NameToURLEncoder .ENCODED_NAME_SUFFIX )).isEqualTo ("/name" );
4040 }
41+
42+ @ Test
43+ public void shouldEncodeSafeNameWithSpace ()
44+ {
45+ assertThat (NameToURLEncoder .encode ("name name" )).isEqualTo ("name+name" );
46+ }
47+
48+ @ Test
49+ public void shouldDecodeSafeNameWithSpace ()
50+ {
51+ assertThat (NameToURLEncoder .decode ("name+name" )).isEqualTo ("name name" );
52+ }
4153}
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ public ComponentsContainer getEditor(AttributeEditContext context)
234234
235235 binder = new SingleStringFieldBinder (msg );
236236 binder .forField (editor , context .isRequired ())
237- .withValidator ((v ,c ) -> validate (v , context ))
237+ .withValidator ((v ,c ) -> validate (v , context . isRequired () ))
238238 .bind ("value" );
239239 binder .setBean (new StringBindingValue (value == null ? "" : value .getValue ()));
240240
@@ -261,9 +261,9 @@ private void onVerifyButtonClick(AttributeEditContext context)
261261 confirm .open ();
262262 }
263263
264- private ValidationResult validate (String value , AttributeEditContext context )
264+ private ValidationResult validate (String value , boolean required )
265265 {
266- if (!context . isRequired () && (value == null || value .isEmpty ()))
266+ if (!required && (value == null || value .isEmpty ()))
267267 return ValidationResult .ok ();
268268 try
269269 {
Original file line number Diff line number Diff line change 1919import io .imunity .vaadin .endpoint .common .plugins .attributes .components .SingleStringFieldBinder ;
2020import io .imunity .vaadin .endpoint .common .plugins .credentials .CredentialEditor ;
2121import io .imunity .vaadin .endpoint .common .plugins .credentials .CredentialEditorContext ;
22+
23+ import org .apache .commons .lang3 .StringUtils ;
2224import org .apache .logging .log4j .Logger ;
2325import pl .edu .icm .unity .base .attribute .AttributeExt ;
2426import pl .edu .icm .unity .base .attribute .AttributeType ;
@@ -201,7 +203,7 @@ private void updateConfirmationStatusIconAndButtons()
201203 formatter .getSimpleConfirmationStatusString (confirmationInfo ),
202204 confirmationInfo .isConfirmed ());
203205 editor .setVerifyButtonVisible (
204- !confirmationInfo .isConfirmed () && !( editor . getValue () == null || editor .getValue (). isEmpty ()));
206+ !confirmationInfo .isConfirmed () && StringUtils . isNotEmpty ( editor .getValue ()));
205207 skipUpdate = true ;
206208 editor .setAdminCheckBoxValue (confirmationInfo .isConfirmed ());
207209 skipUpdate = false ;
Original file line number Diff line number Diff line change 1616import io .imunity .vaadin .endpoint .common .plugins .attributes .components .SingleStringFieldBinder ;
1717import io .imunity .vaadin .endpoint .common .plugins .identities .IdentityEditor ;
1818import io .imunity .vaadin .endpoint .common .plugins .identities .IdentityEditorContext ;
19+
20+ import org .apache .commons .lang3 .StringUtils ;
1921import org .apache .logging .log4j .Logger ;
2022import pl .edu .icm .unity .base .confirmation .ConfirmationInfo ;
2123import pl .edu .icm .unity .base .entity .EntityParam ;
@@ -160,7 +162,7 @@ private void updateConfirmationStatusIcon()
160162 confirmationInfo .isConfirmed ());
161163 }
162164 editor .setVerifyButtonVisible (!confirmationInfo .isConfirmed ()
163- && !( editor . getValue () == null || editor .getValue (). isEmpty ())
165+ && StringUtils . isNotEmpty ( editor .getValue ())
164166 && value != null
165167 && editor .getValue ().equals (value .getValue ()));
166168 skipUpdate = true ;
You can’t perform that action at this time.
0 commit comments