This repository was archived by the owner on Mar 28, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
test/unit/com/structurizr/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,25 +69,30 @@ public static String getImageAsDataUri(File file) throws IOException {
6969 return "data:" + contentType + ";base64," + base64Content ;
7070 }
7171
72- public static void validateImage (String url ) {
73- if (StringUtils .isNullOrEmpty (url )) {
72+ public static void validateImage (String imageDescriptor ) {
73+ if (StringUtils .isNullOrEmpty (imageDescriptor )) {
7474 return ;
7575 }
7676
77- url = url .trim ();
77+ imageDescriptor = imageDescriptor .trim ();
7878
79- if (Url .isUrl (url )) {
79+ if (Url .isUrl (imageDescriptor )) {
8080 // all good
8181 return ;
8282 }
8383
84- if (url .startsWith ("data:image" )) {
85- if (ImageUtils .isSupportedDataUri (url )) {
86- // all good
84+ if (imageDescriptor .toLowerCase ().endsWith (".png" ) || imageDescriptor .toLowerCase ().endsWith (".jpg" ) || imageDescriptor .toLowerCase ().endsWith (".jpeg" ) || imageDescriptor .toLowerCase ().endsWith (".gif" )) {
85+ // it's just a filename
86+ return ;
87+ }
88+
89+ if (imageDescriptor .startsWith ("data:image" )) {
90+ if (ImageUtils .isSupportedDataUri (imageDescriptor )) {
91+ // it's a PNG/JPG data URI
8792 return ;
8893 } else {
8994 // it's a data URI, but not supported
90- throw new IllegalArgumentException ("Only PNG and JPG data URIs are supported: " + url );
95+ throw new IllegalArgumentException ("Only PNG and JPG data URIs are supported: " + imageDescriptor );
9196 }
9297 }
9398
Original file line number Diff line number Diff line change @@ -159,6 +159,10 @@ void validateImage() {
159159 ImageUtils .validateImage ("https://structurizr.com/image.png" );
160160 ImageUtils .validateImage ("data:image/png;base64,iVBORw0KGg" );
161161 ImageUtils .validateImage ("data:image/jpeg;base64,iVBORw0KGg" );
162+ ImageUtils .validateImage ("image.png" );
163+ ImageUtils .validateImage ("image.jpg" );
164+ ImageUtils .validateImage ("image.jpeg" );
165+ ImageUtils .validateImage ("image.gif" );
162166
163167 //disallowed
164168 try {
You can’t perform that action at this time.
0 commit comments