Kaynağa Gözat

Prevent crash on malformed background shorthand

Taddeus Kroes 10 yıl önce
ebeveyn
işleme
abb3154faa
1 değiştirilmiş dosya ile 6 ekleme ve 2 silme
  1. 6 2
      shorthand.ml

+ 6 - 2
shorthand.ml

@@ -111,7 +111,7 @@ let rec unfold = function
     orig :: unfold tl
     orig :: unfold tl
 
 
   (* background: [color] [image] [repeat] [attachment] [position] *)
   (* background: [color] [image] [repeat] [attachment] [position] *)
-  | ("background", Concat values, imp) :: tl ->
+  | (("background", Concat values, imp) as orig) :: tl ->
     let make sub value = ("background-" ^ sub, value, imp) in
     let make sub value = ("background-" ^ sub, value, imp) in
     let id_color = function
     let id_color = function
       | [] -> []
       | [] -> []
@@ -140,7 +140,11 @@ let rec unfold = function
         make "position-y" posy :: make "position-x" posx :: id_attachment tl
         make "position-y" posy :: make "position-x" posx :: id_attachment tl
       | tl -> id_attachment tl
       | tl -> id_attachment tl
     in
     in
-    List.rev (id_pos (List.rev values)) @ unfold tl
+    begin
+      try List.rev_append (id_pos (List.rev values)) (unfold tl)
+      (* instead of crashing, just don't unfold malformed shorthands *)
+      with Box_error _ -> orig :: unfold tl
+    end
   | ("background", (Uri _ as image), imp) :: tl ->
   | ("background", (Uri _ as image), imp) :: tl ->
     ("background-image", image, imp) :: unfold tl
     ("background-image", image, imp) :: unfold tl
   | ("background", color, imp) :: tl ->
   | ("background", color, imp) :: tl ->