Skip to content
This repository has been archived by the owner on Sep 26, 2020. It is now read-only.

Escape profile keys for MongoDB #38

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Xhgui/Saver/Mongo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ public function save(array $data)
$data['_id'] = self::getLastProfilingId();
}

// Escape profile data keys according to the standard https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names
if (isset($data['profile'])) {
$profile = array();
foreach ($data['profile'] as $key => $value) {
$escapedKey = str_replace(array(".", "$"), "_", $key);
$profile[$escapedKey] = $value;
}
$data['profile'] = $profile;
unset($profile);
}

if (isset($data['meta']['request_ts'])) {
$data['meta']['request_ts'] = new MongoDate($data['meta']['request_ts']['sec']);
}
Expand Down