[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 <gzahidi@cisco.com>
This commit is contained in:
Ghufz 2020-04-17 20:38:48 +05:30 committed by GitHub
parent 896867b5e7
commit 0adc20f114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 0 deletions

View File

@ -19,6 +19,7 @@ package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.meta.GeneratorMetadata;
@ -622,6 +623,28 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen
supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml"));
}
@SuppressWarnings("static-method")
@Override
public String escapeText(String input) {
if (input == null) {
return input;
}
// remove \t, \n, \r
// replace \ with \\
// replace " with \"
// outter unescape to retain the original multi-byte characters
// finally escalate characters avoiding code injection
return escapeUnsafeCharacters(
StringEscapeUtils.unescapeJava(
StringEscapeUtils.escapeJava(input)
.replace("\\/", "/"))
.replaceAll("[\\t\\n\\r]", " ")
.replace("\\", "\\\\")
.replace("\"", "\"\""));
}
@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("#>", "#_>").replace("<#", "<_#");

View File

@ -689,6 +689,7 @@ components:
type: string
password:
type: string
pattern: '["A-Z]+-[0-9][0-9]'
phone:
type: string
userStatus:

View File

@ -62,6 +62,7 @@ function Initialize-PSUser {
[String]
${Email},
[Parameter(Position = 5, ValueFromPipelineByPropertyName = $true)]
[ValidatePattern("[""A-Z]+-[0-9][0-9]")]
[String]
${Password},
[Parameter(Position = 6, ValueFromPipelineByPropertyName = $true)]