Skip to content

Commit d9605b5

Browse files
committed
Sort maps alphabetically
1 parent fc78b78 commit d9605b5

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/mapserv-index.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
****************************************************************************/
2727

28+
#include <algorithm>
29+
#include <string>
30+
#include <vector>
31+
2832
#include "mapserver.h"
2933
#include "mapogcapi.h"
3034
#include "mapserv-index.h"
@@ -495,16 +499,25 @@ int msOGCAPIDispatchIndexRequest(mapservObj *mapserv, configObj *config) {
495499
return MS_FAILURE;
496500
}
497501

502+
// Collect keys and sort alphabetically (case-insensitive)
503+
std::vector<std::string> keys;
498504
const char *key = NULL;
499-
json links = json::array();
500-
501505
while ((key = msNextKeyFromHashTable(&config->maps, key)) != NULL) {
502-
if (mapObj *map = getMapFromConfig(config, key)) {
503-
links.push_back(createMapSummary(map, key, request));
506+
keys.push_back(key);
507+
}
508+
std::sort(keys.begin(), keys.end(),
509+
[](const std::string &a, const std::string &b) {
510+
return strcasecmp(a.c_str(), b.c_str()) < 0;
511+
});
512+
513+
json links = json::array();
514+
for (const auto &k : keys) {
515+
if (mapObj *map = getMapFromConfig(config, k.c_str())) {
516+
links.push_back(createMapSummary(map, k.c_str(), request));
504517
msFreeMap(map);
505518
} else {
506519
// there was a problem loading the map
507-
links.push_back(createMapError(key));
520+
links.push_back(createMapError(k.c_str()));
508521
}
509522
}
510523

0 commit comments

Comments
 (0)