Separate server name and id, use hostname-valid encoding#216
Separate server name and id, use hostname-valid encoding#216duncanbeevers wants to merge 3 commits intotypicode:masterfrom
Conversation
c2ea9cd to
a6a7c22
Compare
name and id, id uses hostname-valid encoding
name and id, id uses hostname-valid encodinga6a7c22 to
cb2814f
Compare
| const id = req.params.id | ||
| ? this.resolve(req.params.id) | ||
| : this.resolve(req.hostname.replace(tld, '')) | ||
| const tld = new RegExp(`\\.${daemonConf.tld}$`) |
There was a problem hiding this comment.
The previous regexp here wasn't enforcing a dot.
src/daemon/normalize.js
Outdated
| module.exports = function normalize(id) { | ||
| return id | ||
| ? punycode | ||
| .encode(id) |
There was a problem hiding this comment.
punycode won't mess with existing ASCII; it only ensures that non-ASCII characters get embedded into a hostname-valid space.
| ? punycode | ||
| .encode(id) | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9-.]/g, '-') |
There was a problem hiding this comment.
This ensures that ASCII characters such as spaces, parentheses, commas, and so on, are encoded to a hostname-valid space.
| .encode(id) | ||
| .toLowerCase() | ||
| .replace(/[^a-z0-9-.]/g, '-') | ||
| .replace(/-+/g, '-') |
There was a problem hiding this comment.
Because so many characters are replaced by hyphen, any run of multiple hyphens is collapsed to a single hyphen.
cb2814f to
0d45259
Compare
|
@typicode ping |
0d45259 to
1a40140
Compare
1a40140 to
04f3e65
Compare
|
This PR has been updated to incorporate the changes from the UI refactor. |
src/app/components/Nav/index.css
Outdated
| } | ||
|
|
||
| .listLink { | ||
| line-height: 1em; |
| @@ -0,0 +1,12 @@ | |||
| const punycode = require('punycode') // eslint-disable-line node/no-deprecated-api | |||
|
|
|||
| module.exports = function normalize(name) { | |||
There was a problem hiding this comment.
Why the ternary, have you spotted a case where it can can be undefined or is it for safety?
Could you write some tests for normalize or add a comment with examples of inputs and expected outputs?
| .toLowerCase() | ||
| .replace(/[^a-z0-9-.]/g, '-') | ||
| .replace(/-+/g, '-') | ||
| .replace(/-$/, '') |
There was a problem hiding this comment.
Not sure to understand what they're for?
.replace(/-+/g, '-')
.replace(/-$/, '')There was a problem hiding this comment.
It’s to ensure that multiple invalid characters only get replaced by one -, and to remove trailing -s.
There was a problem hiding this comment.
Yes, this is just for tidiness sake. In the examples I posted server names include whitespace followed by non-alpha-numeric characters resulting in double hyphens.
It looks a little cleaner to me to tidy them, but the code I wrote mostly applies to my own naming scheme. For example, it doesn't remove leading hyphens, but that's only because I'd never named a server something that would result in a leading hyphen.
I'm happy to simplify this entire section and simply use the pure punycode replacements. That seems less likely to result in id collisions where multiple similarly-named servers normalize to the same server id.
package.json
Outdated
| "npm-run-all": "^4.1.2", | ||
| "pkg-ok": "^1.0.1", | ||
| "prettier": "^1.10.2", | ||
| "punycode": "^2.1.0", |
There was a problem hiding this comment.
Could you move it to dependencies as it's used in the daemon?
|
Thanks for the PR :) (and the style fix) I'd like to understand better, the idea is to be to have "pretty" names for files and automatically get valid domain? Something like: ~/.hotel/servers/My Server (something).json # my-server-something.localhostWhat does your projects directories look like? Do they have |
|
@typicode The filenames represent the displayed values, like so: In some cases, parameterizable hotel servers would alleviate this, as many of the configurations are very similar to one another with the modification of one or two command-line flags. |
34e21c3 to
8813baf
Compare


If you name your
~/.hotel/serversfiles using non-uri characters, they aren't recognized by theexistsmiddleware.This PR allows intuitive, human-friendly naming of these files, and a more beautiful list of servers.
