Skip to content

Commit

Permalink
[powershell-experimental] ValidatePattern with double-quote (") throw…
Browse files Browse the repository at this point in the history
…s-exception (OpenAPITools#5956)

* ValidatePattern having double quote(") throws exception on running Build.ps1

* fix tab with space

Co-authored-by: Ghufran Zahidi <[email protected]>
  • Loading branch information
2 people authored and michaelpro1 committed May 7, 2020
1 parent 8869f75 commit d9da36b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -622,6 +623,28 @@ public void processOpts() {
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("<#", "<_#");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ components:
type: string
password:
type: string
pattern: '["A-Z]+-[0-9][0-9]'
phone:
type: string
userStatus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit d9da36b

Please sign in to comment.