-
Notifications
You must be signed in to change notification settings - Fork 131
Protect from exceptions in decodeURIComponent; do not url-encode span context #105
Conversation
…code span context
import SpanContext from '../src/span_context'; | ||
|
||
describe ('TextMapCodec', () => { | ||
it('should not URL-decode value that has no % meta-characters', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is insufficient because decodeURIComponent(abc)
returns abc
. We should explicitly verify that decodeURIComponent('abc')
has never been called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, but I am not sure how to do that. @saminzadeh is there a way to mock standard functions?
src/propagators/text_map_codec.js
Outdated
if (this._urlEncoding && value.indexOf('%') > -1) { | ||
// unfortunately, decodeURIComponent() can throw 'URIError: URI malformed' | ||
try { | ||
return decodeURIComponent(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saminzadeh do you know if there's an alternative std function that never throws exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If decodeURIComponent
is hard to mock, I'm ok with merging this
* Adds Metrics API https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/metrics-api.md adds gauge and counter types checkpoint checkpoint update docs update index.ts move todo * yarn check
decodeURIComponent can throw
URIError: URI malformed
when unable to parse the string.The string representation of the context is #:#:#:# (# is hex digits), so it is "safe" to be used as is in the http header value without URL encoding.