Просмотр исходного кода

LibWeb: Make sure Blob type is not outside range 0x0020-0x007E

This makes sure that type is set to an empty string if
BlobPropertyBag::type is outside the range 0x0020 to 0x007E.
Kenneth Myhra 2 лет назад
Родитель
Сommit
c8c5f05de5
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      Userland/Libraries/LibWeb/FileAPI/Blob.cpp

+ 9 - 2
Userland/Libraries/LibWeb/FileAPI/Blob.cpp

@@ -132,10 +132,17 @@ DOM::ExceptionOr<NonnullRefPtr<Blob>> Blob::create(Optional<Vector<BlobPart>> co
     String type = String::empty();
     String type = String::empty();
     // 3. If the type member of the options argument is not the empty string, run the following sub-steps:
     // 3. If the type member of the options argument is not the empty string, run the following sub-steps:
     if (options.has_value() && !options->type.is_empty()) {
     if (options.has_value() && !options->type.is_empty()) {
-        // FIXME: 1. Let t be the type dictionary member. If t contains any characters outside the range U+0020 to U+007E, then set t to the empty string and return from these substeps.
+        // 1. If the type member is provided and is not the empty string, let t be set to the type dictionary member.
+        //    If t contains any characters outside the range U+0020 to U+007E, then set t to the empty string and return from these substeps.
+        //    NOTE: t is set to empty string at declaration.
+        if (!options->type.is_empty()) {
+            if (is_basic_latin(options->type))
+                type = options->type;
+        }
 
 
         // 2. Convert every character in t to ASCII lowercase.
         // 2. Convert every character in t to ASCII lowercase.
-        type = options->type.to_lowercase();
+        if (!type.is_empty())
+            type = options->type.to_lowercase();
     }
     }
 
 
     // 4. Return a Blob object referring to bytes as its associated byte sequence, with its size set to the length of bytes, and its type set to the value of t from the substeps above.
     // 4. Return a Blob object referring to bytes as its associated byte sequence, with its size set to the length of bytes, and its type set to the value of t from the substeps above.