Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/357#discussion_r21098987
  
    --- Diff: 
software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java
 ---
    @@ -73,6 +74,23 @@
     
         private static final Logger LOG = 
LoggerFactory.getLogger(BindDnsServerImpl.class);
     
    +    // As per RFC 952 and RFC 1123.
    +    private static final CharMatcher DOMAIN_NAME_FIRST_CHAR_MATCHER = 
CharMatcher.inRange('a', 'z')
    +                .or(CharMatcher.inRange('A', 'Z'))
    +                .or(CharMatcher.inRange('0', '9'));
    +    private static final CharMatcher DOMAIN_NAME_MATCHER = 
DOMAIN_NAME_FIRST_CHAR_MATCHER
    +            .or(CharMatcher.is('-'));
    +
    +
    +    private class HostnameTransformer implements Function<Entity, String> {
    +        @Override
    +        public String apply(Entity input) {
    +            String hostname = 
input.getAttribute(getConfig(HOSTNAME_SENSOR));
    +            hostname = 
DOMAIN_NAME_FIRST_CHAR_MATCHER.negate().trimFrom(hostname);
    +            return DOMAIN_NAME_MATCHER.retainFrom(hostname);
    --- End diff --
    
    ```
    hostname = 
DOMAIN_NAME_FIRST_CHAR_MATCHER.negate().trimLeadingFrom(hostname);
    return DOMAIN_NAME_MATCHER.negate().trimAndCollapseFrom(hostname, '-');
    ```
    
    This would be better, it only removes disallowed characters from the start, 
and replaces anything else disallowed in the body of the string with `-`.
    
    There's length restrictions too, 63 characters per segment and 255 
characters overall maximum.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to