diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index f018aab5c95..8b2d08fb963 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -589,4 +589,36 @@ JS::Value convert_a_key_to_a_value(JS::Realm& realm, GC::Ref key) VERIFY_NOT_REACHED(); } +// https://w3c.github.io/IndexedDB/#valid-key-path +bool is_valid_key_path(KeyPath const& path) +{ + // A valid key path is one of: + return path.visit( + [](String const& value) -> bool { + // * An empty string. + if (value.is_empty()) + return true; + + // FIXME: * An identifier, which is a string matching the IdentifierName production from the ECMAScript Language Specification [ECMA-262]. + return true; + + // FIXME: * A string consisting of two or more identifiers separated by periods (U+002E FULL STOP). + return true; + + return false; + }, + [](Vector const& values) -> bool { + // * A non-empty list containing only strings conforming to the above requirements. + if (values.is_empty()) + return false; + + for (auto const& value : values) { + if (!is_valid_key_path(value)) + return false; + } + + return true; + }); +} + } diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h index 2814a282127..7bc329ffca6 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -13,6 +14,8 @@ namespace Web::IndexedDB { +using KeyPath = Variant>; + WebIDL::ExceptionOr> open_a_database_connection(JS::Realm&, StorageAPI::StorageKey, String, Optional, GC::Ref); bool fire_a_version_change_event(JS::Realm&, FlyString const&, GC::Ref, u64, Optional); ErrorOr> convert_a_value_to_a_key(JS::Realm&, JS::Value, Vector = {}); @@ -21,5 +24,6 @@ GC::Ref upgrade_a_database(JS::Realm&, GC::Ref, u64 WebIDL::ExceptionOr delete_a_database(JS::Realm&, StorageAPI::StorageKey, String, GC::Ref); void abort_a_transaction(IDBTransaction&, GC::Ptr); JS::Value convert_a_key_to_a_value(JS::Realm&, GC::Ref); +bool is_valid_key_path(KeyPath const&); }