URL Encoding Project Alias - quality-manager/onboarding GitHub Wiki

Development guidance on URL Encoding and Project Alias

How is a project alias created?

The alias is created at the time of project creation. It is derived from the name of the project. It is the x-www-form-urlencoded form of the name, but also may be modified if there are duplicates of the project name. So you can not always know what the alias is by just knowing the name. See the ProjectAliasService class for reference.

x-www-form-urlencoded encoding scheme

This encoding scheme is done on the project alias so it can be placed as a segment on the URL. However, this was not the correct scheme to be applied to a URL segment. This type of encoding is only meant for HTTP Form submissions and parameter values on the query string of a URL. It is incompatible with the URI path segment encoding.

Example:

'A + B' x-www-form-urlencoded    = 'A+%2B+B'
'A + B' URI path segment RFC3986 = 'A%20+%20B'

Since x-www-form-urlencoded has been in place since QM 1.0, we have to continue to support this encoding scheme.

What is the structure of a QM URL with project alias?

<------------------------- standard encoding -------------------------><--alias--><-standard->

.../service/com.ibm.rqm.integration.service.IIntegrationService/resources/A+%2B+B/executionresult

  • All parts of the URI use standard URI encoding except the project alias segment
  • The project alias segment is used as-is. We do not encode or decode this segment of the URI.

Development Rules

  • ServerURI class should be the default choice for building or modifying URL's
    • ServerURI will properly handle excluding the alias segment of the path from encoding or decoding as the alias should always be used as-is stored in the DB
    • ServerURI is also safe to use on non project aliased URL's as it detects what is the project alias segment of supported URL's
    • ServerURI properly handles per segment path encoding so that we can support external ID's with non alpha numeric characters
  • Use URI class only when passing along a URI, but not modifying
    • Use only the URI(String uri) constructor as it will not modify the URI
    • When the URI class is used, the user must understand its API as many methods will automatically encode or decode values causing problems with a URL containing project alias.
    • The URI class is also not fully supportive of the URI spec. It doesn't handle per path segment encoding and decoding, but this is implemented in our ServerURI class
  • URL class does not perform any encoding or decoding. Use only when passing along, but not modifying
  • PDF should never encode or decode any URL's anymore. All such code was removed. When it is necessary to modify a URL, it should now only use ServerURI.
  • Nowhere in the product should we ever encode or decode the project alias. It must only be used as the value stored in the DB.

Client Rules

  • Project alias value is opaque.
    • Project alias value should be obtained from the project feed service
    • Do not attempt to derive the project alias from the project name or the name from the alias.
  • Project alias should only be used as-is when part of a path segment of a URL.
    • Note, some URL API's for some libraries and languages may automatically encode or decode path segments. When constructing URL's be sure to use API's that use the raw value when setting the path.
  • When project alias is part of a URL parameter, the entire parameter value should be encoded as you would normally encode any parameter value for HTML form submission via GET or POST using application/x-www-form-urlencoded w3 org forms

Examples

URL segment with alias A+%2B+B

https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/A+%2B+B/testscript/urn:com.ibm.rqm:testscript:2

URL which contains a parameter with alias within value

We want to set the fields parameter to value feed/entry/content/testplan/testcase[@href='https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/A+%2B+B/testcase/testcase2?oslc_config.context=_2QCggKblEeq_g_5OO_ryVA']

URL should be constructed as following where the value of fields is x-www-form-urlencoded:

https://localhost:9443/qm/service/com.ibm.rqm.integration.service.IIntegrationService/resources/A+%2B+B/testplan?fields=feed%2Fentry%2Fcontent%2Ftestplan%2Ftestcase%5B%40href%3D%27https%3A%2F%2Flocalhost%3A9443%2Fqm%2Fservice%2Fcom.ibm.rqm.integration.service.IIntegrationService%2Fresources%2FA%2B%252B%2BB%2Ftestcase%2Ftestcase2%3Foslc_config.context%3D_2QCggKblEeq_g_5OO_ryVA%27%5D

References:

⚠️ **GitHub.com Fallback** ⚠️