OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Symfony] Backslashes in namespaces passed to the Assert\Type ctor are not escaped
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix ([example]
Description
Version 4.3.0
If any part of the namespace of a type starts with an escape character, the string is mangled (contains a unicode or non-printable character) when passed to the constructor to Assert\Type.
Generated code for the controller with "invokerPackage": "Api\\v1" in the configuration file:
// Deserialize the input values that needs it
try {
$body = $this->deserialize($body, 'Api\v1\Model\MyType', $inputFormat);
} catch (SerializerRuntimeException $exception) {
return $this->createBadRequestResponse($exception->getMessage());
}
// Validate the input values
$asserts = [];
>>> $asserts[] = new Assert\Type("Api\v1\Model\MyType");
$asserts[] = new Assert\Valid();
$response = $this->validate($body, $asserts);
Here \v is converted to the vertical tab character.
Suggest a fix
Escape the backslashes or use single quotes for the string passed to the constructor of Assert\Type
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Symfony generator templates or entry points responsible for emitting controller validation code, using the reported invokerPackage value "Api\v1" to reproduce the generated Assert\Type line. Verify the generated PHP preserves namespace backslashes and no longer converts sequences such as \v into control characters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100