Bug 1448945 - Allow underscore in category, method and extra keys of event. r=chutten

According to the documnetation[1] category and method are identifiers,
thus an underscore is allowed. It's less clear for extra keys, but
underscores are already used there.

The documentation is adjusted accordingly.

[1]: https://firefox-source-docs.mozilla.org/toolkit/components/telemetry/telemetry/collection/events.html#limits

MozReview-Commit-ID: 9pUsDNXCY8m
This commit is contained in:
Jan-Erik Rediger
2018-04-10 13:05:39 +02:00
parent af5cde507e
commit 4b94fa0f85
2 changed files with 4 additions and 4 deletions

View File

@@ -981,7 +981,7 @@ TelemetryEvent::RegisterEvents(const nsACString& aCategory,
MOZ_ASSERT(XRE_IsParentProcess(), MOZ_ASSERT(XRE_IsParentProcess(),
"Events can only be registered in the parent process"); "Events can only be registered in the parent process");
if (!IsValidIdentifierString(aCategory, 30, true, false)) { if (!IsValidIdentifierString(aCategory, 30, true, true)) {
JS_ReportErrorASCII(cx, "Category parameter should match the identifier pattern."); JS_ReportErrorASCII(cx, "Category parameter should match the identifier pattern.");
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
@@ -1065,7 +1065,7 @@ TelemetryEvent::RegisterEvents(const nsACString& aCategory,
// Validate methods. // Validate methods.
for (auto& method : methods) { for (auto& method : methods) {
if (!IsValidIdentifierString(method, kMaxMethodNameByteLength, false, false)) { if (!IsValidIdentifierString(method, kMaxMethodNameByteLength, false, true)) {
JS_ReportErrorASCII(cx, "Method names should match the identifier pattern."); JS_ReportErrorASCII(cx, "Method names should match the identifier pattern.");
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
@@ -1085,7 +1085,7 @@ TelemetryEvent::RegisterEvents(const nsACString& aCategory,
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
for (auto& key : extra_keys) { for (auto& key : extra_keys) {
if (!IsValidIdentifierString(key, kMaxExtraKeyNameByteLength, false, false)) { if (!IsValidIdentifierString(key, kMaxExtraKeyNameByteLength, false, true)) {
JS_ReportErrorASCII(cx, "Extra key names should match the identifier pattern."); JS_ReportErrorASCII(cx, "Extra key names should match the identifier pattern.");
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }

View File

@@ -43,7 +43,7 @@ Where the individual fields are:
- ``method``: ``String``, identifier. This describes the type of event that occurred, e.g. ``click``, ``keydown`` or ``focus``. - ``method``: ``String``, identifier. This describes the type of event that occurred, e.g. ``click``, ``keydown`` or ``focus``.
- ``object``: ``String``, identifier. This is the object the event occurred on, e.g. ``reload_button`` or ``urlbar``. - ``object``: ``String``, identifier. This is the object the event occurred on, e.g. ``reload_button`` or ``urlbar``.
- ``value``: ``String``, optional, may be ``null``. This is a user defined value, providing context for the event. - ``value``: ``String``, optional, may be ``null``. This is a user defined value, providing context for the event.
- ``extra``: ``Object``, optional, may be ``null``. This is an object of the form ``{"key": "value", ...}``, both keys and values need to be strings. This is used for events where additional richer context is needed. - ``extra``: ``Object``, optional, may be ``null``. This is an object of the form ``{"key": "value", ...}``, both keys and values need to be strings, keys are identifiers. This is used for events where additional richer context is needed.
.. _eventlimits: .. _eventlimits: