diff --git a/include/valijson/schema_parser.hpp b/include/valijson/schema_parser.hpp index 4404b2b..706ffd5 100644 --- a/include/valijson/schema_parser.hpp +++ b/include/valijson/schema_parser.hpp @@ -170,6 +170,25 @@ private: return true; } + /** + * Sanitise an optional JSON Pointer, trimming trailing slashes + */ + std::string sanitiseJsonPointer(const boost::optional input) + { + if (input) { + // Trim trailing slash(es) + std::string sanitised = *input; + sanitised.erase(sanitised.find_last_not_of('/') + 1, + std::string::npos); + + return sanitised; + } + + // If the JSON Pointer is not set, assume that the URI points to + // the root of the document + return ""; + } + /** * @brief Populate a Schema object from JSON Schema document * @@ -543,8 +562,8 @@ private: internal::json_reference::getJsonReferenceUri(jsonRef); // Extract JSON Pointer from JSON Reference - const std::string jsonPointer = - internal::json_reference::getJsonReferencePointer(jsonRef); + const std::string jsonPointer = sanitiseJsonPointer( + internal::json_reference::getJsonReferencePointer(jsonRef)); if (documentUri) { // Resolve reference against remote document