Comments (13)
This looks like a case for a new Domainkey validator
from zend-validator.
I second this. Maybe some sort of option to permit this pattern?
from zend-validator.
Using underscores in hostnames can cause more problems on network level. See also 'Restrictions on valid hostnames' on https://en.wikipedia.org/wiki/Hostname.
Also; actually the underscore is the uppercase for "-", as it comes when shift plus "-" are pressed. ;) All hostnames are lowercase.
from zend-validator.
why it is impossible to realize optional check?
from zend-validator.
@bacinsky all known dns of the server support validation of underscore in hostname long ago, but developers refer to RFC.
from zend-validator.
@bacinsky You should've known in the first place that underscores are illegal characters for (sub)domainnames, so you can't expect a whole framework to bend for it, just because you want to and because you lack proper implementations. You really should read the Wikipedia article I linked before, as it clearly explaines why an underscore can't be correctly used in hostnames.
from zend-validator.
@bacinsky If you've read the Wikipedia article, you've seen that underscores can be used for something else within DNS. More specific:
While a hostname may not contain other characters, such as the underscore character (_), other DNS names may contain the underscore. Systems such as DomainKeys and service records use the underscore as a means to assure that their special character is not confused with hostnames. For example, _http._sctp.www.example.com specifies a service pointer for an SCTP capable webserver host (www) in the domain example.com. Note that some applications (e.g. Microsoft Internet Explorer) won't work correctly if any part of the hostname contains an underscore character.
So my actual advice is to proper implement things like they were intended to, to avoid problems later on.
As hostnames officially can't have underscores, I'd return an error, stating underscores are not allowed, rather than try to look for options to work around it, hoping to fix it (what you did).
from zend-validator.
@CptChaos "underscore can't be correctly used in hostnames" - please proof. DKIM,DMARC,SRV,TLSA - properly works.
from zend-validator.
@038291 You've actually just proven my point exactly. DKIM, SRV, DMARC, TLSA and such aren't hostnames. More info upon the subject; read the linked wikipedia article and try to read about DNS and how it works and what it's (im)possibilities are.
from zend-validator.
@CptChaos Leaves so that it is necessary to write the separate DNS RRSet's validator. Hostname validator isn't suitable for these purposes. Thanks.
ps: http://domainkeys.sourceforge.net/underscore.html
from zend-validator.
I solved this problem in a tricky way. I created an FqdnValidator. It has two options: allowUnderscore and allowWildcard. The FqdnValidator internally uses the Zend Hostname validator.
First, the FQDN string (e.g. abc.example.com) is split into the TLD (com), domain (example) and subdomain (abc) parts. It is a little bit against the official terminology, but what is important, is that the underscore as well as a wildcard (*) characters are only allowed for some DNS Records and only as a subdomain part.
So, when the allowUnderscore option is enabled, the underscore is replaced with 'x' character in all subdomains. The domain part (i.e. 'example') is not affected. The string is passed then to the Hostname validator.
When the allowWildcard option is enabled, each subdomain part is checked if it contains only one character and this character is the asterix (*). If this assertion is ok, the asterix is replaced with 'x' and passed to the Hostname validator.
The hardest thing to do here is to split the FQDN into the parts. For instance, some TLDs contain dot inside, i.e. in both cases example.de.com and example.com the domain name part is 'example'. You'll need to maintain the list of TLDs to achieve this splitting.
Sorry, but I can not share the solution I did because the FqdnValidator is a Symfony validator and the list of TLDs is loaded from the DB dynamically.
from zend-validator.
@038291 Sorry for the late response. On the page you linked, you can also read:
'Names that are not host names can consist of any printable ASCII character.'
So yes, hostnames (like for web addresses) actually can't have a _ in them. ;)
@crzdeveloper How would you solve this when a subdomain has an x in it, like when you have example.example2.tld? ;) I would also no use a DB to store tld's, but rather configfiles or something similar. It's not likely TLD's are going to change much. ;) Keeping it from a DB makes it a bit faster, as you do not have to build another connection, query the database and wait for the results.
from zend-validator.
This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at laminas/laminas-validator#27.
from zend-validator.
Related Issues (20)
- Missing support for emojis as valid punycode HOT 1
- ZF3 Using Explode with InArray validator as child breaks validation messages format HOT 1
- EmailAddress - validateInternationalizedLocalPart method optional?
- Valid hostnames are consideres invalid with Umlaut and certain TLDs HOT 1
- Running URI through UriNormalize Filter appends `/` - causes Hostname TLD check to always fail HOT 2
- Method visibility bug HOT 5
- Hostname validator produces notice on empty domainPart HOT 1
- NoRecordExists and RecordExists does not work when exclude paramter is of cass Where HOT 2
- Validator for .DE domains outdated (lack of 'sharp s' support)
- Hostname validation not correct when not checking TLD
- Maybe bug in testMoscowWinterTime
- Zend_Validate_CreditCard return the valid type? HOT 1
- Proposal: Validation for breached passwords HOT 18
- AbstractValidator does not use messageKey when translating messages HOT 5
- cannot assign translator object to validator. HOT 7
- Can not translate messages from the FileUploadFile validator. HOT 4
- update for php 7.2 HOT 1
- Fatal error: Uncaught Error: Class 'Zend\Uri\Uri' not found HOT 1
- Hash and Crc32 validator issue if hash has only digits HOT 3
- container-interop/container-interop is abandoned, replace with psr/container HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zend-validator.