@@ -22,6 +22,7 @@ import * as Skeleton from "../utils/skeleton";
2222import * as CustomBackgroundFilter from "../elements/custom-background-filter" ;
2323import {
2424 ConfigValue ,
25+ CustomBackgroundSchema ,
2526 CustomLayoutFluid ,
2627} from "@monkeytype/contracts/schemas/configs" ;
2728import {
@@ -1108,11 +1109,21 @@ $(".pageSettings .sectionGroupTitle").on("click", (e) => {
11081109$ (
11091110 ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton button.save"
11101111) . on ( "click" , ( ) => {
1111- UpdateConfig . setCustomBackground (
1112- $ (
1113- ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton input"
1114- ) . val ( ) as string
1115- ) ;
1112+ const newVal = $ (
1113+ ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton input"
1114+ ) . val ( ) as string ;
1115+
1116+ const parsed = CustomBackgroundSchema . safeParse ( newVal ) ;
1117+
1118+ if ( ! parsed . success ) {
1119+ Notifications . add (
1120+ `Invalid custom background URL (${ parsed . error . issues [ 0 ] ?. message } )` ,
1121+ 0
1122+ ) ;
1123+ return ;
1124+ }
1125+
1126+ UpdateConfig . setCustomBackground ( newVal ) ;
11161127} ) ;
11171128
11181129$ (
@@ -1125,11 +1136,21 @@ $(
11251136 ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton input"
11261137) . on ( "keypress" , ( e ) => {
11271138 if ( e . key === "Enter" ) {
1128- UpdateConfig . setCustomBackground (
1129- $ (
1130- ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton input"
1131- ) . val ( ) as string
1132- ) ;
1139+ const newVal = $ (
1140+ ".pageSettings .section[data-config-name='customBackgroundSize'] .inputAndButton input"
1141+ ) . val ( ) as string ;
1142+
1143+ const parsed = CustomBackgroundSchema . safeParse ( newVal ) ;
1144+
1145+ if ( ! parsed . success ) {
1146+ Notifications . add (
1147+ `Invalid custom background URL (${ parsed . error . issues [ 0 ] ?. message } )` ,
1148+ 0
1149+ ) ;
1150+ return ;
1151+ }
1152+
1153+ UpdateConfig . setCustomBackground ( newVal ) ;
11331154 }
11341155} ) ;
11351156
0 commit comments