Skip to content

Commit 0adc20f

Browse files
authored
[powershell-experimental] ValidatePattern with double-quote (") throws-exception (#5956)
* ValidatePattern having double quote(") throws exception on running Build.ps1 * fix tab with space Co-authored-by: Ghufran Zahidi <[email protected]>
1 parent 896867b commit 0adc20f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.swagger.v3.oas.models.media.ArraySchema;
2020
import io.swagger.v3.oas.models.media.Schema;
2121
import org.apache.commons.io.FilenameUtils;
22+
import org.apache.commons.lang3.StringEscapeUtils;
2223
import org.apache.commons.lang3.StringUtils;
2324
import org.openapitools.codegen.*;
2425
import org.openapitools.codegen.meta.GeneratorMetadata;
@@ -622,6 +623,28 @@ public void processOpts() {
622623
supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml"));
623624
}
624625

626+
@SuppressWarnings("static-method")
627+
@Override
628+
public String escapeText(String input) {
629+
630+
if (input == null) {
631+
return input;
632+
}
633+
634+
// remove \t, \n, \r
635+
// replace \ with \\
636+
// replace " with \"
637+
// outter unescape to retain the original multi-byte characters
638+
// finally escalate characters avoiding code injection
639+
return escapeUnsafeCharacters(
640+
StringEscapeUtils.unescapeJava(
641+
StringEscapeUtils.escapeJava(input)
642+
.replace("\\/", "/"))
643+
.replaceAll("[\\t\\n\\r]", " ")
644+
.replace("\\", "\\\\")
645+
.replace("\"", "\"\""));
646+
}
647+
625648
@Override
626649
public String escapeUnsafeCharacters(String input) {
627650
return input.replace("#>", "#_>").replace("<#", "<_#");

modules/openapi-generator/src/test/resources/3_0/powershell/petstore.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ components:
689689
type: string
690690
password:
691691
type: string
692+
pattern: '["A-Z]+-[0-9][0-9]'
692693
phone:
693694
type: string
694695
userStatus:

samples/client/petstore/powershell-experimental/src/PSPetstore/Model/User.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function Initialize-PSUser {
6262
[String]
6363
${Email},
6464
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)]
65+
[ValidatePattern("[""A-Z]+-[0-9][0-9]")]
6566
[String]
6667
${Password},
6768
[Parameter(Position = 6, ValueFromPipelineByPropertyName = $true)]

0 commit comments

Comments
 (0)