Skip to content

Commit

Permalink
fix: check for api url service subfolders, query, and fragment (#234)
Browse files Browse the repository at this point in the history
* fix: check for url subfolders

* fix: check for fragment and query in api service URI
  • Loading branch information
stew-ro authored May 4, 2020
1 parent f6c8ffa commit 04a1696
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"apiUriBase": {
"title": "Form recognizer service URI",
"description": "Form recognizer service URI",
"type": "string",
"format": "uri"
"type": "string"
},
"apiKey": {
"title": "API key",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"apiUriBase": {
"title": "Form recognizer service URI",
"description": "Form recognizer service URI",
"type": "string",
"format": "uri"
"type": "string"
},
"apiKey": {
"title": "API key",
Expand Down
12 changes: 12 additions & 0 deletions src/react/components/pages/projectSettings/projectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ export default class ProjectForm extends React.Component<IProjectFormProps, IPro
Object.keys(project.sourceConnection).length === 0) {
errors.sourceConnection.addError("is a required property");
}
if (project.apiUriBase && errors.apiUriBase) {
const urlRegex = new RegExp(/^(https?:\/\/)([\w\-])+\.([a-zA-Z]{2,63})/);
if (urlRegex.test(project.apiUriBase)) {
if ((project.apiUriBase.match(/\//g) || []).length > 2 ||
(project.apiUriBase.match(/\?/g) || []).length > 0 ||
(project.apiUriBase.match(/#/g) || []).length > 0) {
errors.apiUriBase.addError("should contain only protocol and domain name");
}
} else {
errors.apiUriBase.addError("should match URI format");
}
}

if (this.state.classNames.indexOf("was-validated") === -1) {
this.setState({
Expand Down

0 comments on commit 04a1696

Please sign in to comment.