or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-2/

URL Parameter Encoder

Build a utility that encodes URL parameters according to RFC 3986 standards for use in OAuth and other security-sensitive contexts.

Capabilities

Encodes standard URL parameters

  • Given the parameter { user: "john@example.com", message: "Hello World!" }, the encoded query string is user=john%40example.com&message=Hello%20World%21 @test
  • Given the parameter { callback: "http://example.com/auth?token=abc123" }, the encoded query string is callback=http%3A%2F%2Fexample.com%2Fauth%3Ftoken%3Dabc123 @test

Encodes special characters per RFC 3986

  • Given the string "hello(world)", the encoded result is "hello%28world%29" @test
  • Given the string "user's data", the encoded result is "user%27s%20data" @test
  • Given the string "test*value!", the encoded result is "test%2Avalue%21" @test

Handles Unicode characters

  • Given the string "私のさえずり" (Japanese text), the encoded result is "%E7%A7%81%E3%81%AE%E3%81%95%E3%81%88%E3%81%9A%E3%82%8A" @test
  • Given the parameter { text: "Café ☕" }, the encoded query string is text=Caf%C3%A9%20%E2%98%95 @test

Implementation

@generates

API

/**
 * Encodes a string according to RFC 3986 percent-encoding rules.
 * Encodes all characters that encodeURIComponent encodes, plus: ! * ( ) '
 *
 * @param {string} str - The string to encode
 * @returns {string} The RFC 3986 percent-encoded string
 */
function encodeRFC3986(str) {
  // IMPLEMENTATION HERE
}

/**
 * Encodes an object of parameters into a query string with RFC 3986 encoding.
 * Keys and values are sorted alphabetically by key name.
 *
 * @param {Object} params - Object with string keys and string values
 * @returns {string} Encoded query string in format "key1=value1&key2=value2"
 */
function encodeParams(params) {
  // IMPLEMENTATION HERE
}

module.exports = {
  encodeRFC3986,
  encodeParams,
};

Dependencies { .dependencies }

oauth-sign { .dependency }

Provides RFC 3986 percent-encoding support for OAuth-compliant URL encoding.

@satisfied-by