git » sdk » commit 05256b0

Don't fail if the letter is invalid

author Stephen Paul Weber
2025-03-23 02:01:19 UTC
committer Stephen Paul Weber
2025-03-23 02:01:19 UTC
parent 87682bb807535713f6d83d73d7887500a32e70c0

Don't fail if the letter is invalid

snikket/Color.hx +7 -2

diff --git a/snikket/Color.hx b/snikket/Color.hx
index 537992c..3d3f454 100644
--- a/snikket/Color.hx
+++ b/snikket/Color.hx
@@ -17,11 +17,16 @@ class Color {
 	}
 
 	public static function defaultPhoto(input:String, letter:String) {
-		var hex = forString(input).substr(1);
+		final hex = forString(input).substr(1);
+		final encodedLetter = try {
+			StringTools.urlEncode(letter);
+		} catch (e) {
+			" ";
+		}
 		return
 			'data:image/svg+xml,<svg%20xmlns="http://www.w3.org/2000/svg"%20version="1.1"%20width="15"%20height="15"%20viewBox="0%200%2015%2015">' +
 			'<rect%20style="fill:%23' + hex + ';"%20width="15"%20height="15"%20x="0"%20y="0"%20/>' +
-			'<text%20style="fill:%23ffffff;font-size:8px;font-family:sans-serif;"%20text-anchor="middle"%20dominant-baseline="central"%20x="50%25"%20y="50%25">' + StringTools.urlEncode(letter) + '</text>' +
+			'<text%20style="fill:%23ffffff;font-size:8px;font-family:sans-serif;"%20text-anchor="middle"%20dominant-baseline="central"%20x="50%25"%20y="50%25">' + encodedLetter + '</text>' +
 			'</svg>';
 	}
 }