Skip to content

Bug: Index out of range exception thrown when a 404 would be expected #435

@atuttle

Description

@atuttle

Suppose you have an API with ONLY the following URI implemented: /api/v1/index.cfm/pizza/{topping}

  • If a request arrives for /api/v1/index.cfm/pizza we currently return a 404. This is good. 👍🏻
  • If a request arrives for /api/v1/index.cfm/pizza/ we currently throw an exception. This is bad. 👎🏻

The problem is that an empty-string is an acceptable match for tokens. This behavior should continue. There are valid reasons to expect and allow empty-string as a token value.

However, in this case, when buildRequestArguments executes, it doesn't account for this possibility. We would expect a response in the shape of { topping: "" }. Instead an error is thrown while trying to reference the token here (line 1015).

Taffy/core/api.cfc

Lines 1009 to 1017 in ce987af

<!--- parse path_info data into key-value pairs --->
<cfset local.tokenValues = reFindNoSuck(arguments.regex, arguments.uri) />
<cfset local.numTokenValues = arrayLen(local.tokenValues) />
<cfset local.numTokenNames = arrayLen(arguments.tokenNamesArray) />
<cfif local.numTokenNames gt 0>
<cfloop from="1" to="#local.numTokenNames#" index="local.t">
<cfset local.returnData[arguments.tokenNamesArray[local.t]] = local.tokenValues[local.t] />
</cfloop>
</cfif>

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions