Skip to content

string parameters are url encoding issue #534

Closed
@paolosanchi

Description

@paolosanchi

The value of any parameter is urlencoded to the route, but it isn't urldecoded when converted back to parameter, this causes the engine detect it as changed and it causes a navigation.

format()

      // If the parameter type is "raw", then do not encodeURIComponent
      if (param.raw) return acc + encoded;
      // Encode the value
      return acc + encodeURIComponent(<string>encoded);

exec()

    for (let i = 0; i < nPathSegments; i++) {
      const param: Param = pathParams[i];
      let value: any | any[] = match[i + 1];

      // if the param value matches a pre-replace pair, replace the value before decoding.
      for (let j = 0; j < param.replace.length; j++) {
        if (param.replace[j].from === value) value = param.replace[j].to;
      }
      if (value && param.array === true) value = decodePathArray(value);
      if (isDefined(value)) value = param.type.decode(value);
      values[param.id] = param.value(value);
    }
    searchParams.forEach(param => {
      let value = search[param.id];
      for (let j = 0; j < param.replace.length; j++) {
        if (param.replace[j].from === value) value = param.replace[j].to;
      }
      if (isDefined(value)) value = param.type.decode(value);
      values[param.id] = param.value(value);
    });

I think this would be solved change the exec() to something like this:

    for (let i = 0; i < nPathSegments; i++) {
      const param: Param = pathParams[i];
      let value: any | any[] = match[i + 1];

      // if the param value matches a pre-replace pair, replace the value before decoding.
      for (let j = 0; j < param.replace.length; j++) {
        if (param.replace[j].from === value) value = param.replace[j].to;
      }
      if (value && param.array === true) value = decodePathArray(value);
      if (isDefined(value)){
		value = param.type.decode(value);
		if(typeof value === 'string' && !param.raw){
			value = decodeURIComponent(value);
		}
	  }
      values[param.id] = param.value(value);
    }
    searchParams.forEach(param => {
      let value = search[param.id];
      for (let j = 0; j < param.replace.length; j++) {
        if (param.replace[j].from === value) value = param.replace[j].to;
      }
      if (isDefined(value)){
		value = param.type.decode(value);
		if(typeof value === 'string' && !param.raw){
			value = decodeURIComponent(value);
		}
	  }
      values[param.id] = param.value(value);
    });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions