Skip to content

Commit

Permalink
feat(options): URL validation in Preferences
Browse files Browse the repository at this point in the history
- URLs must match specific pattern
- Invalid URL is highlighted and not saved
  • Loading branch information
lidel committed Oct 8, 2017
1 parent 6bb4ba1 commit 3565061
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions add-on/src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
border: 1px solid #3E9398;
box-shadow: 0 0 5px #5FCBCF;
}
input:invalid {
border: 1px solid #933E98;
box-shadow: 0 0 5px #CB5FCF;
}
</style>
<script src="../lib/npm/browser-polyfill.min.js"></script>
</head>
Expand All @@ -80,7 +84,8 @@
<dd>URL of preferred HTTP2IPFS&nbsp;Gateway</dd>
</dl>
</label>
<input type="url" id="customGatewayUrl" inputmode="url" required pattern="https?://[^/].+"/>
<input type="url" id="customGatewayUrl" inputmode="url" required
pattern="^https?://[^/]+$" spellcheck="false" title="Enter URL without any sub-path" />
</div>
<div>
<label for="useCustomGateway">
Expand All @@ -98,7 +103,8 @@
<dd>Fallback URL used when Custom Gateway is not available and for copying shareable links</dd>
</dl>
</label>
<input type="url" id="publicGatewayUrl" inputmode="url" required pattern="https?://[^/]+"/>
<input type="url" id="publicGatewayUrl" inputmode="url" required
pattern="^https?://[^/]+$" spellcheck="false" title="Enter URL without any sub-path" />
</div>
</fieldset>
</form>
Expand All @@ -112,7 +118,8 @@
<dd>Hint: this is where <code>/webui</code> lives</dd>
</dl>
</label>
<input type="url" id="ipfsApiUrl" inputmode="url" required pattern="https?://[^/]+"/>
<input type="url" id="ipfsApiUrl" inputmode="url" required
pattern="^https?://[^/]+$" spellcheck="false" title="Enter URL without any sub-path" />
</div>
<div>
<label for="ipfsApiPollMs">
Expand Down
4 changes: 4 additions & 0 deletions add-on/src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

async function saveOption (name) {
const element = document.querySelector(`#${name}`)
if (!element.checkValidity()) {
console.warn('[ipfs-companion] Invalid value for option: ' + name)
return
}
if (element) {
const change = {}
switch (element.type) {
Expand Down

0 comments on commit 3565061

Please sign in to comment.