diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt index 90a9d41a18..f263ae1816 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestCallAction.kt @@ -166,7 +166,9 @@ class RestCallAction( /** * Make sure that the path params are resolved to the same concrete values of "other". - * Note: "this" can be just an ancestor of "other" + * Note: "this" can be just an ancestor of "other". + * This function takes care when path elements are dynamically handled based on + * results of previous calls (eg a POST creating a resource). * * **/ fun bindToSamePathResolution(other: RestCallAction) { @@ -189,11 +191,38 @@ class RestCallAction( g.forceNewTaints() } } + if(this.path.isEquivalent(other.path)) { + //if pointing to the same resource, make sure to handle dynamic resource creation + //TODO does it make sense to do it even for ancestor paths??? likely not... but not 100% sure + this.usePreviousLocationId = other.usePreviousLocationId + this.weakReference = other.weakReference + } } - fun usingSameResolvedPath(other: RestCallAction) = - //FIXME this does not consider dynamic fields? - this.resolvedOnlyPath() == other.resolvedOnlyPath() + /** + * Check if the resulting path of this action is the same of [other], taking into account dynamic info + */ + fun usingSameResolvedPath(other: RestCallAction) : Boolean{ + if(this.path.levels() != other.path.levels()){ + return false + } + + /* + TODO Is this really correct? what about cases of + 1) /items/{id}/foo + 2) /items/{id}/bar + ??? + TODO we need to handle the possible non-shared suffix + */ + if(this.usePreviousLocationId != null && this.usePreviousLocationId == other.usePreviousLocationId){ + return true + } + if(this.weakReference != null && this.weakReference == other.weakReference){ + return true + } + + return this.resolvedOnlyPath() == other.resolvedOnlyPath() + } /** * When the URL path of this endpoint is resolved, would it be a (strict) parent from the other action diff --git a/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt b/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt index 4e1439b4e6..6ca918471a 100644 --- a/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt +++ b/core/src/main/kotlin/org/evomaster/core/problem/rest/data/RestPath.kt @@ -263,7 +263,7 @@ class RestPath(path: String) { return false } - return (0 until this.elements.size).none { other.elements[it] != this.elements[it] } + return this.elements.indices.none { other.elements[it] != this.elements[it] } }