Merge branch 'MDL-70970-39' of git://github.com/paulholden/moodle into MOODLE_39_STABLE

This commit is contained in:
Andrew Nicols 2021-04-23 11:39:52 +08:00
commit 1b169c82be

View file

@ -34,9 +34,9 @@ use CFPropertyList\CFNumber;
use CFPropertyList\CFPropertyList; use CFPropertyList\CFPropertyList;
use CFPropertyList\CFString; use CFPropertyList\CFString;
use CFPropertyList\CFType; use CFPropertyList\CFType;
use \Collator;
use \DateTime; use \DateTime;
defined('MOODLE_INTERNAL') || die();
/** /**
* Wrapper for CFPropertyList to handle low level iteration. * Wrapper for CFPropertyList to handle low level iteration.
@ -322,6 +322,8 @@ class property_list {
/** /**
* Recursively sort array alphabetically by key. * Recursively sort array alphabetically by key.
* *
* @link https://safeexambrowser.org/developer/seb-config-key.html
*
* @param array $array Top level array to process. * @param array $array Top level array to process.
* @return array Processed array. * @return array Processed array.
*/ */
@ -331,10 +333,23 @@ class property_list {
$array[$key] = $this->array_sort($array[$key]); $array[$key] = $this->array_sort($array[$key]);
} }
} }
// Sort assoc array. From SEB docs - "Use non-localized (culture invariant), non-ASCII value based case // Sort assoc array. From SEB docs:
// insensitive ordering." //
// All <dict> elements from the plist XML must be ordered (alphabetically sorted) by their key names. Use
// a recursive method to apply ordering also to nested dictionaries contained in the root-level dictionary
// and in arrays. Use non-localized (culture invariant), non-ASCII value based case insensitive ordering.
// For example the key <key>allowWlan</key> comes before <key>allowWLAN</key>. Cocoa/Obj-C and .NET/C#
// usually use this case insensitive ordering as default, but PHP for example doesn't.
if ($this->is_associative_array($array)) { if ($this->is_associative_array($array)) {
ksort($array, SORT_STRING | SORT_FLAG_CASE); // Note this is a pragmatic solution as none of the native PHP *sort method appear to sort strings that
// differ only in case (e.g. ["allowWLAN", "allowWlan"] is expected to have the lower version first).
$keys = array_keys($array);
(new Collator('root'))->asort($keys); // Use Unicode Collation Algorithm (UCA).
$original = $array;
$array = [];
foreach ($keys as $key) {
$array[$key] = $original[$key];
}
} }
return $array; return $array;