5 kyu
Extract the domain name from a URL
3,771 of 83,324xianpants
Loading description...
Parsing
Regular Expressions
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Lovely Kata, I really like working with strings.
5 Kyu?? It's very esay
This comment has been hidden.
This comment has been hidden.
Groovy Translation
I'm pretty open for changes on this translation since it may not be 100% the same as in the Python translation
Improved Java translation
Is there a problem or are there multiple problems with the Java translation or why is it not being merged?
From a glance:
Missing assertion messages in sample and fixed tests
Adding unnecessary code block to description, which creates potential of merge conflicts for other published translations.
Lack of test coverage and edge cases (refer to the issues raised in this kata) and also picking sub-sections of an email from a given collection of items is not so random
You can also see there are a lot of translations pending, which is associated with the point mentioned earlier. ^^
There is mistake bcz he never mentioned that there will be invalid url which is basically dfkljasidjfosdj.com. So instructions unclear and kata should be fixed to avoid confusions
I would've solved this had I know that the only possible subdomain is "www".
Description not detailed enough. It should be clarified that www is the only subdomain and http(s):// the only protocol being tested against.
Current solutions will not work reliably for most real-world URL's.
Here are some url-patterns that should also be tested:
The wording of the description is confusing as it actually wants a hostname returned, not a domain name. Aditionally, I encountered issues around the .co.za TLD
hey, I'm getting this error (first letter of sime tests being left out) 'yphen-site' should equal 'hyphen-site' does anyone have any suggestions as to why this might be in my code?
If this kata is to be an exercise in regular expressions, its description should be updated to indicate that it is not looking for the actual domain in the URL, only a kind of approximation to it.
Because practically every solution that is currently accepted is incorrect--when using a more accurate definition of "domain".
For example, most solutions seem to hardcode "www." as being the only possible (optional) sub-domain. So that given the URL "subdomain.domain.tld", many solutions would return "subdomain" as the domain. And given the URL "nested.subdomain.domain.co.uk", many solutions would return "nested" as the domain.
I scrolled through a few ~pages of solutions, and not one of them would be able to accurately return the domain in those cases. Even the solution I submitted is not complete.
I understand the intent of the kata as an exercise for regular expressions, but it should be updated to reflect the fact that isn't actually looking for a proper domain (unless my definition of domain is different from everyone else's).
This comment has been hidden.
The function
domainName
should only have one argument. The domain name is the solution you have to return.Is it normal to get this error when i test my code?
Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import domain_name ImportError: cannot import name 'domain_name' from 'solution' (/workspace/default/solution.py)
Aparently something went wrong.. not my code
you must use the given function name
(so, yes, your code)
not a kata issue
This comment has been hidden.
Use the spoiler flag please.
showing your code is not a suggestion. you are not supposed to reveal code / methods to others that haven't solved the kata yet, anyway. so, that's why your comment is spoilered. a suggestion is intended for when you have an idea on how to improve the kata
All is wrong, the kata doesn't won't to extract a domain and also it's not extracted from an URL...
URL: https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL
Domain: contains www., .co.jp, blog. all not only google from www.google.co.jp
Would be better if the description specified that the test cases are not expecting sub-domains (other than www). Most of the solutions here (including mine ;)) would fail on a URL like https://dev.example.com/.
I know you want write a one-line solution, however it may cause you a lot of pain. Sometimes it is better to break problem into peaces and do tricks with the input.
This comment has been hidden.
Scala translation
python new test frame work
Approved
C# translation ready! Please review and approve.
I can't determine from the kata description what assumptions we are allowed/expected to make. I don't think we can assume that a subdomain will be 'www' - and you cannot assume what a subdomain might be, so you realy must start from the TLD. Once the effective TLD is determined, get the domain and ignore any subdomains if there is one.
This is kind of a non-trivial problem that requires the use of the "requests" package to rerieve the list of effective top-level-domains from https://publicsuffix.org/list/public_suffix_list.dat
That is not a spoiler - the url should have been in the question, of the question should have explicitely given either a list of TLDs or Subdomains.
Poorly written question.
This comment has been hidden.
Please read https://datatracker.ietf.org/doc/html/rfc1808.html. The problem makes zero sense as currently written.
it would have been nice to have instruction point out that the subdomains would only be
www
if any to be present. without it, compiling complex regex might have been dodged in my case, wasting hours for an amateur problemThis comment has been hidden.
Hints are not kata suggestions. See https://docs.codewars.com/training/troubleshooting#post-discourse
I didn't like it. I wrote several solutions that worked in the test, but were useless later. If there is extensive testing, I would like to see how the wobbly ones look like, to understand where I am wrong...
You can use
print(url)
at the start of your function to print it on console output. That way, you can see the url provided to the function.This comment has been hidden.
This comment has been hidden.
Very simple kata, thanks! :D
This comment has been hidden.
In real world, subdomain can be anything and not just "www". In this question, all subdomains (if exist) are "www", and I think this should be mentioned in the question.
This comment has been hidden.
you are not the only one
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Print function argument to console.
Thank you for your reply, and I'm sorry for being so ignorant here, but do you mean copy the whole STDERR into the code and print it?
@AlexDRichards - if you read the Troubleshooting guide it means:
insert a line in your code that prints to console the argument that your function receives. So here, you are being passed an URL string - let's say it's called "input_URL_string" in Ruby, I don't know exactly: then in your code just after the function definition include a line like
console.log(input_URL_string)
, or however you do this in Ruby language.now press Attempt as usual - each time your code is run in a Codewars test, it will display in the Codewars console on your screen the contents of the input that was received for that test (both the ones that your code passes and the ones that fail); so in this kata you will see a bunch of strings representing URL names appearing in your console.
look in the console for the Red messages, and now you can see the inputs which caused your failed tests
This worked! Thank you! (I tried this same approach on another kata, and the output was a gigantic block of text that caused a timeout, but for this kata it worked perfectly to help me debug, thanks!)
Most if not all posted solutions are incorrect.
A URL may have any number of subdomains, and may have a large variety of suffixes (see: https://publicsuffix.org/list/).
For example:
http://some.subdomain.mail.google.sth.ac.at
Is a valid URL. This project attempts to address the problem, but is clearly beyond the scope of this Kata (as it is marked #regex): https://github.com/lupomontero/psl.
The instructions should be modified to state what subdomains and suffixes are allowed.
How is this an issue though? (Its just a miswording not an issue, the problem tells you what you need to do, so just do it or find other problems if you aren't satisfied with that detail).
Note that the test cases do not include any url with more than two dots in prior to the first
/
, likewww.google.co.uk
. It could be a good idea to include this kind of url, which could change an accepted answer somewhat.This comment has been hidden.
Please don't post solutions in Discourse.
This comment has been hidden.
This comment has been hidden.
don't post code without the spoiler tag, I just added it to your comment
also, there is no
question
here ... (?1) this code passes the kata. there is no point in posting your solutionok sory can i delete it? i cant see that option
This comment has been hidden.
Tests show what test cases you fail:
Your solution returned
"www"
in the first case, andundefined
in the second, which are not correct answers.Your solution has a bug. Bug in your solution is not a kata issue.
A valid url is "xwww.com" but some implemntations would fail because they replace "www." with nothing rather than looking for "www." at the start.
So I suggest this added as a testcase.
This comment has been hidden.
Please don't post solutions in Discourse.
I was looking to try it in Typescirpt.
Not found.
Then i decided that i can translate it.
But i found out there is pending typescript translation
Maybe someone can approve this (or make some comments, so we could improve it and finally merge)?
This comment has been hidden.
This comment has been hidden.
Your solution is buggy and it does not process the
"www.xakep.com"
corectly.Not a kata issue.
.
I already know the solution is buggy. That is why I wrote I "worked around." There were not enough random test.
I can appreciate what it was going for, but this kata is not a great problem-solving exercise because the requirements are not specific enough.
It should be specified that the test cases will only ever have zero or one subdomains, and if it has one, it will always be "www." In the real world, URLs might include multiple subdomains (that could be anything) and a multi-part top-level domain (e.g. "host.sub1.sub2.domain.co.jp") so the premise is already too vague.
A better exercise would be one that requires you to check an input URL against a predefined set of formatting rules (e.g. there will only be one subdomain, it may or may not have "http(s)", there will be no invalid characters, etc.), and return the domain name if it conforms to those rules, or an error/null if it does not.
This comment has been hidden.
I'm dealing with the same issue. How did you fix it?
To clarify: the name of my function is exactly the same as when the kata started. I have tested 25+ URLs and it returns the expected output. However, the attempts fail.
If you write your code in your IDE on your PC, then paste it into Codewars, you must make sure that the function name is the same as the one that is visible in the "default"/starting screen on the Codewars kata page - because the tests will be expecting to import that named function.
So if a kata asks for a function "count_to_ten" and you call it "my_test_function_on_my_pc" then it won't work.
Thanks for the response!
This comment has been hidden.
think about how the
counter
variable is incremented, and how it affects the if blockThis comment has been hidden.
read this
not a kata issue
This comment has been hidden.
I spent way too long on this when I realised my initial code wasn't going to "correctly" handle subdomains. After a lot of thought, frustration, re-writes and tests in my IDE, I went back to my original code out of frustration. Expecting to get errors, so I could check what was actually being tested. To my surprise, Test ... passed, Attempt ... passed.
As other comments have indicated, a more encompasing description and/or additional examples would really have helped here. This really is a case of writing code to fit specific test case expectations, instead of test case verifying a workable solution.
Anyway ... time to move on, too much time spent on this one now.
Feel free to suggest improvements to the description. Once you solved a kata, you are even able to fork it and propose a new description's version (click
fork
on top right).I feel you man... i wasn't expecting to spend as much time as i did on this task...
'https://youtube' should equal 'youtube'
pardon if I sound frustrated. but, is that even a valid URL? should that testcase be allowed?
You are misreading the log: it tells you "your_answer should equal the correct_answer". Your function returns 'https://youtube' for the input 'https://youtube.com', which is incorrect.
oh. my bad. thank you for pointing it out.
good kata
This comment has been hidden.
Don't post solutions in discourse please. And use proper code formatting.
This comment has been hidden.
This comment has been hidden.
I don't know much about python, but is it possible you renamed your function?
Save your code locally, make sure you have the latest language version selected (Python 3.8), push
reset
at the bottom page and it should fix the issue.@akar-0 thanks that helped
This comment has been hidden.
Please use a spoiler flag.
This comment has been hidden.
This comment has been hidden.
approved
for some reason it says I passed all tests except the basic one, which returns 'net' instead of '123' :< is it a problem in my code or a bug?
The basic test you are refering to expects
123
. It's a problem with your code, though if your code fails only on this one it also means tests should be enhanced with adding some similar random tests (which means your code should not pass all the other tests if they were complete).true I literally can passed the kata using the same code and adding 1 line just to solve that expecific sample test, very unsatisfactory. I'll have to keep trying to solve it without that trick
Could you post your incorrect code with a spoiler flag please? I've just controlled JS tests and I'm surprised an incorrect solution could pass, I'd like to see where is failing your code, in order to suggest improvements and take it in account in a new translation I am preparing.
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
It'd be helpful to have more test cases in the main "Details" section that way we don't write an algorithm and then have to change it once we figure out that there are test cases we haven't accounted for
such as
"https://www.3bdnxqyar-dczn.br/index.php" (has wwww after the //) or "kpxfxwp9kh3en.us" (has no prefix www or //)
This comment has been hidden.
Use
console.log()
to see the inputs for which your code fails, then try to find what they all have in common.Your code can't handle file endings. So any url with
.html
or.php
at the end will fail.Hi everybody! My solution was accepted. But I'm understand that it doesent work with url's like "www.textwww.com"
yes me too
it means your solution is wrong/not working for edge cases
This comment has been hidden.
That your code returned
'nn'
when it should have returned'icann'
, read this: https://docs.codewars.com/training/troubleshooting/ and print the input.What do you mean ? What input ?? I don't even know how to check that "icann" test and how it looks like. I apologize for my lack of clue :/
Write
console.log(url)
inside your function, see the input value for the test your code fails, figure out why.OP passed the kata, closing.
This comment has been hidden.
Your code being wrong is not a kata issue, read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
not enough details to be a valid issue. please specify the language and complete input + expected value
This comment has been hidden.
Your code is wrong, see the input of the tests your code fails, there are addresses with only one dot.
thank you
Is there a url like "www.abcwww.com"?
This comment has been hidden.
not a kata issue, please use the
Question
label to ask for help :)The instructions are terrible and do not fully describe the expected behavior. Sure, it could be argued that the solver shouldn't assume "http(s)://" will always be in the URL, even though all three examples have it, but I'm talking about stuff like what should be done about URL's such as "www.images.google.co.jp/". Should the solution return "images"? "images.google"? "google"?
The instructions need a lot of work explaining the behavior of the solution, or at least fully characterizing the output of solutions.
This comment has been hidden.
a bit obsolete?? only has node v8.1.3 (thats 4 a version made years ago) would recomend that you update it please. Did it on node v17.0.1 works and all but now i need to adapt it for node v8.1.3 and im not doing that.
The latest Node's vesion available in CW is 12 at the moment. I've updated the tests to use that version. Version 17 is not available and there is no ETA for it.
ok thanks ill just book mark the kata and wait xd
This comment has been hidden.
This is a good point. Random or not, a proper test set should have at least one test for each combination of input traits. Suppose the set of input traits is {hasHttp, hasHttps, hasWww, hasSLD, hasSubdomain, hasFilenameAtEnd}, where each trait is true or false. For all combinations of true and false values for those traits, the test set should include a URL that satisfies those traits.
The test cases in this kata are wrong
FYI the TLD should be part of the domain name (.com/.org/.ru etc)
THe first cases weren't bad. It was the long list. There were just so many variations that you had to account for seperately. That's the hint. Sometimes, there isn't a one CASE fits all.
why can I not work with tldextract?
This module is not installed in the CW environment.
This comment has been hidden.
this was broken. Since many solutions would not even work on real sites.
What definition for 'domain name' is used for this kata? Can you provide a reference for the definition? The answers appear to be using a definition that is different/inconsistent with Section 2.3.1 of RFC-1035 Domain Names - Implementation and Specification.
It is also inconsistent with ICANNs definition https://www.icann.org/en/icann-acronyms-and-terms/domain-name-en. "A domain name consists of two or more textual segments separated by dots."
This comment has been hidden.
This comment has been hidden.
I'm not sure if this is a mistake or we should have a function predict the output. I have 8 x '' empty urls which have random generated test assertions like below : '' should equal 'lz1azqi6wztabr3e' '' should equal 'rayl80wqeq5' '' should equal 's5amw9ozevzcmrcuoys2vo' '' should equal 'z0bnifstlw2afsius1ywnt166roh' '' should equal 'nfdxo5rb1jt1mmx8ncs0pn2w7lgxa' '' should equal 'kaoszjrgt9b5173ijk' '' should equal 'uxot2egwyxk7p' Can this be clarified if the test assertions are incorrect ? Thank you.
It says what you returned and what you should have returned.
Ic thanks
some url do not have "https, http and www" they just have domain name like google.com
I'm able to get it to pass for all the test cases that are listed. But when I attempt it fails, and I'm not sure what url is failing it. Would be nice if the test cases were expanded and I could write my code accordingly : O.
I agree
debug using print thru each stage from input to output
This comment has been hidden.
I feel like you should add non https requests like http:// and ftp://, as those are both valid URLs that are not covered by your tests
Regular expressions are so satisfying! Great Kata, thanks xianpants!
Some suggestions for improve test cases:
'http://www.google.com' 'https://api.github.com' 'http://google.com' 'https://google.com.br' 'google.com' 'google.com.br' 'docs.google.com' 'http://docs.google.com'
All cases above should return 'google'
'https://api.github.com' 'All cases above should return google' mfw
The test cases seem to make assumptions that the problem statement does not specify. It wasn't as clear as it could've been about what we were actually shooting for.
this kata needs a recent version of node.js to be able to use
new URL(url)
, see https://nodejs.org/dist/latest-v14.x/docs/api/url.html#url_the_whatwg_url_apiNode 14 is not available on CW, and it has already been requested to be added. Not an issue.
I have resloved a similar quesion in a real project. My main method was
publicsuffix2
(https://pypi.org/project/publicsuffix2/).This module allows you to get the public suffix, as well as the registrable domain, of a domain name using the Public Suffix List from http://publicsuffix.org
A nice and simple kata.
My code worked on all of the test cases, but some of the other cases for the attempt were still wrong. Are there any other 'markers' like www that are included in the basic test cases but not in the final one?
You can print the input.
the url awww.com should be added to the test suite.
This comment has been hidden.
This comment has been hidden.
Totally agree. The problem/solution is superficial. A real solution requires importing a list valid TLDs. PSL by Mozilla is probably a good place to start
Easy but interesting!
This one is interesting. It helped me think about domain names, which actually made it pretty straightforward.
This comment has been hidden.
Thanks I am also trying URL and getting the error. It should be mentioned that you can't use URL.
I'm having an issue that I can't figure out here. I can get "www.", "https://" etc. to be ignored, but for some reason in the test cases where the domain starts with with one of those letters (w or h for example), it ignores that letter and matches the rest of the domain name. I have no idea why its grabbing that one extra letter. Other than that all the other cases are passing. Any one got any suggestions?
Are you starting from 1 instead of 0?
I suggest that the url
secure.ftp.g.cn
be added to the test suite.g
is the domain name.secure
andftp
are two subdomains and the TLD iscn
.The url is fictitious but g.cn is a real website while multiple sub-domains are a possibility.
I'd be curious to see your solution in this case. :)
I just did a version guessing using the most common patterns. It has most of the failures as the other solutions but with comments explicitly pointing out the issues.
You should be able to click 'View Solution' under my post to see it. If not then this link should work: https://www.codewars.com/kata/reviews/553a8bb91e0399d6f70001b9/groups/5ff1ed99f0bb620001b79f96
This comment has been hidden.
Very poorly designed kata. Please revise tests with edge cases (subdomain being different than "www" at the very least). State your assumptions.
have errors ? make this text: url="http://google.com" url="www.google.com" url="http://www.google.com" url="google.com"
This comment has been hidden.
I tested my solution with: "http://geoNOTgoogle.test.geo.com"
It returns "geoNOTgoogle" ... shouldn't it return "geo"? If yes, you should add a test case for multiple "." in the url
Looks like you''ve solved it ~~
I am more or less every time surprised about the different solutions and ways of thinking about the problem.
Great way to learn and widen the own horizont. THANK YOU!
Nice kata. But for a kyu 5 way too easy. Should be a 6 or even a 7 in my opinion
Please be my mentor
I appreciate the spirit behind this kata. However, it needs a significant rework or needs to be retired.
I would recommend specifying a subset of the real world functionality like
However, if you took these suggestions then the problem is not very interesting anyway.
I agree. Also, in Node.js there is URL constructor available where you can parse the host easily then in JS we also have location.host. So why reinvent the wheel.
The easiet way is with tld module but I can't import it. Error: no module named tld
Not an issue. This library is not available on CW.
I think the details of the exercise should be more clear about what a URL may or may not contain for this exercise. As said in other comments, the exercise doesn't make it clear that www is the only possible sublevel domain of the test cases.
This comment has been hidden.
where on earth did s come from?
This comment has been hidden.
you're probaly using a class in re which contain a "w" that why w is removed from search.Try to look at other failed result see if it's common and in your failed resutls one result must saying that you're missing a "h" in search(same cause)
I think I misunderstand something. For me it was not possible to distinguish between subdomain and SLD, without importing a list (I took the one from publicsuffix.org). But I can see now the only subdomain is www., which makes the exercice quite easier :-). OK more people pointed this out.
My code fails seven test cases but if I check those fail cases in my console I get the correct expected answer. Is it possible for someone to review my code or am I probably just wrong in my code?please advise?
just print() the code like you do in your console
My solution is not passing all test cases. For example, I get '' should equal '123' What does that even mean? This is not explained at all in the description. If it told me what the expected output should be for all inputs I would add that to my function, but it's not written anywhere.
I agree, this is not a good question right now. Without a given list of second level domains it is not possible to extract the "domain" (which is also not the correct name as pointed out by others). For example: www.museum.tt should return "www", because "mesuem.tt" is actually a SLD that can be registered (same as .co.uk). There is a npm packages that solves this problem:
https://github.com/lupomontero/psl
As mentioned it contains a complete list of all registerable SLD's.
well I am a beginner so I can not fully tell if it's a good question or not but with regex you can get the Domain as long as you write right Regex it dose not matter what domain contains as long as it contain a "." after Domain for ex:- "youtube.notcom/mypage"
Bad kata because conditions are specified unclear, and 'domain' term is specified incorrectly. And actually there are no valid solution without using a big database of public suffix list.
Are somebody can say before googling, if alt.za, of.by, and pvt.ge are regular domains, or subdomains of alt.za, of.by, and pvt.ge are sold to an unlimited number of people by the registrars? In this, and thousands of similar cases, should we detect "alt" as domain or no?
Exactly! I was only thinking about subdomain when answerin this kata & even that is enough to disqualify the "best practice" given :(
Agree. After failing the .co.jp sample test case I started wondering what is actually the 'domain' of a url, if not the first subdomain under the TLD? I figured there was no way I could find it from a url -- if I had used my brains a bit more I could have come up with .co.uk and maybe .co.au, but not .co.jp, and I have know idea how many of those suffixes I am unaware of... Since I am not a pro by a long shot, I forfeited and checked the highest ranked answers, and I see that they fail for most other cases that I had covered (ftp://, subdomains, www.org). I don't want to say Bad kata, because it did help me learn a lot, but it can certainly be improved.
This comment has been hidden.
you are trying to split a variable that is undefined or is == ''. you have to handle those cases before you try to split or you will get that error.
If you need to do something similar in real life it will be much simpler and effective to maintain an updated list of TLDs in your app. This kata is a good example of being asked for a quick fix to a problem that would be better served with other techniques in the long term.
This question omits the possibility that the domain name may not be the first thing you encounter after a possible "www." or "https?://". For example, a possible domain name could have been https://forum.dingdong.com. I am not sure what kind of a regex could catch it.
This comment has been hidden.
This comment has been hidden.
it's forbidden to post code without a spoiler tag. yet, why are you posting your code for no reason? please don't
This comment has been hidden.
looks like you've solved it ~~
This comment has been hidden.
This is not a good question
This comment has been hidden.
read the docs about
re.match
;)This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Returns "Time: 558ms" without further result.
Issue not specified properly.
you need add testcase by yourself
I find 5 kyu katas either too hard or too easy :D P.S. I started my journey in coding only a month ago :)
com.net.awwway.com/heywww mail.google.co.uk bad.oldsite.geocities.ugh/whatabout_file_extensions.html so many missing test cases
Agreed, and I think another interesting case will be 'https://www.org' from the World Wide Web Consortium
Add ihatethewww.com this will break so many naive approaches (including mine)
Thanks for the kata. Tests for fuzzy data should be necessary IMHO. Especially in educational training.
LOL In python it literally says to make your own examples... wtf.
suggestions for test cases for Python:
news.organisation.org news.organisation.co.uk ftp://ftp.members.important-club.org.uk/http http://http.com http://https.co.uk/?q=http://www.example.com/http
the description should really make more clear if you are seriously wanting all correct url's to pass, or only the urls that look 'common' as the test cases are now. I dont think you really want a parser for all correct urls, because the rules are supercomplicated (https://www.ietf.org/rfc/rfc2396.txt not even implemented correctly by some older browsers). so if you want simpler rules, lay them out...
This comment has been hidden.
Done.
@xianpants, thanks for this nice kata! Cheers)
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
No you won't unfortunately.
You're missing a bracket at the end. Maybe you copy-pasted it incorrectly. Also, you should return the answer, not print it to the console.
I believe the problem is im returning the url as 'url' instead of "url". So the problem is single quotation vs double quotation. Any ideas how to fix this?
EDIT:
It looks like from the python documentation that the re module automatically returns strings in that form... should the kata be changed to accept answers in single quotations?
https://docs.python.org/3/library/re.html
There is no difference between single and double quotes in Python
You code would work fine if you added the missing bracket, removed a pair of quote marks, and returned the answer.
This comment has been hidden.
This comment has been hidden.
I like how this is 5kyu and I destroyed it in a few seconds. Seems that the difficulty is mostly reading into the mind of the author, rather than actually solving the problem.
Old kata => easy kata... ;)
This comment has been hidden.
The only way to do this properly is to write a function that checks for all the TLDs that have two parts (co.uk, co.sg, co.il, etc.). Technically the first part of the hostname does not have to be www. For example, it can be mail.zombie-thing.co.uk. Since it would be tedious to collect all the TLDs that have two parts, I'll just assume that the subdomain can only be www. The question should make the expectations clearer. Others have pointed it out, it is not very well formulated.
Thank you. The tests actually show you where you messed up instead of saying "INCORRECT"
The task is misleading and the tests are flawed in many ways. The domain name for
http://google.com
isgoogle.com
notgoogle
. In that example,google
is theSLD
andcom
is theTLD
, see wikipedia for reference. The description should specify what are we looking for in a way that it doesn't provide a bad example (calling theSLD
thedomain name
). Due to this it also fails to categorise things such asexample.co.uk
. From the description I'd assume in this case we are looking to returnexample
, however that would be quite hard to tell as in truth theSLD
here isco
.The tests don't cover many cases, for example (ignoring my note above about the invalidity of the task itself):
I assume he meant to extract the SLD, but I agree this should be clarified in the description. Furthermore I have to say, that testcases would be nice and you should also include the original URLs in the optional message.
test.assert_equals(domain_name("http://example.com"), "example", "Testing http://example.com")
I passed, but I don't like my code. I can think of edge cases that it will get wrong that obviously weren't asked for.
It's interesting that this (like many things) is more complicated than it seems at first, and I'm grateful for the thought it provoked, but for something I'm throwing a few minutes at, it's impossible not to cheat and see what sticks.
This comment has been hidden.
Use regex and not a kata issue
My code manages all the test cases and even "www.xakep.ru", however the python test just responds with an "Error"... Perhaps remove Python as a choice?
I enjoyed this Kata. It was an intersting challenge on parsing within a certain set of rules. Any Kata where I finished having learned a little more about how to use the language is a good one and this was just that.
For all of you who do not want to write test cases, copy and paste the following into your test-case-screen. These worked for me and are based mostly on info from the instructions:
describe "Solution" do it "should test for something" do Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"), "github", "acerroblanco's test case #1") Test.assert_equals(domain_name("http://www.zombie-bites.com"), "zombie-bites", "acerroblanco's test case #2") Test.assert_equals(domain_name("https://www.cnet.com"), "cnet", "acerroblanco's test case #3") Test.assert_equals(domain_name("www.xakep.ru"), "xakep", "acerroblanco's test case #4") end end
Gives error on whatever I try to write into the function. Even print(url) is giving error. Please fix.
Which language?
What error?
Python, In test cases. I guess there are no test cases written for this Kata.
That is why there is that error.
it seems pretty easy for a 5 kyu kata, especially that some basic test cases are not covered. It should be great to add them to make it a 5, and not to have a basic string parsing to solve it.
I understand it's a practice on pure string operations... but why bother when you have better modules (urlparse) for it?
What we are trying to extract here is just the name of the website, not the domain name. The domain name includes the domains after the dot. cnet.com would be the domain name while cnet would be just a website name.
Even that doesn't properly explain the problem. There is no 'name of the website' in the context of a domain name, just subdomains and a top-level-domain.
For example 'sub3.sub2.sub1.com' is a valid domain name, but undefined for this problem.
This kata uses incorrect interpretations of terms, essentially making warriors use trial and error to determine the problem's criteria.
'www.xakep.ru' is not a URL, it's missing the mandatory scheme (such such as 'https') and the associated colon and slash(es). A domain name includes subdomains (such as 'www.') and the top-level-domain (such as '.com).
The portion we are trying to extract doesn't even make sense in the context of many valid domain names (such as 'a.b.c.d')
I agree, it would be nice at least to include this case in the examples
Wish I could double-upvote this.
This comment has been hidden.
I got tripped up on "www.xakep.ru"... the test returned "None is not equal to xakep". What the heck? Is it expecting "xakep" or None? I tried both but it gives me the same error regardless. I wish I could view the actual test to determine what it is trying to do.
@bcode The exact error message is this:
None should equal 'xakep'
(I guess you're doing it in Python, you didn't say) and it means your code is returningNone
and it should be returning'xakep'
instead.Enjoyed this kata and already have put it to use in a project
I was answering the question in python and got the error message:
Response received but no data was written to STDOUT or STDERR
I have the same issue. Any ideas out there?
Same. Not really sure what that means.
The same, maybe the author leave the chance to write tests to us
You get that message when you attempt to run the example tests when there are none. If there are no tests to run nothing happens and no data is written to STDOUT or STDERR. Write some tests!
If you see that, unfortunately you just need to attempt it and work from that without testing.
This comment has been hidden.
What about http://www.google.com.ua/query?
I like how simple and straightforward this one is--and practical.
What about subdomains? I.e. in the URL:
http://sub-domain.domain.com/path?query=string
"google" is not "the domain"... "google.com" is the domain...!
This comment has been hidden.
I am recieveing a failed attempt when I submit. Not sure how to figure it out without the URL... Any tips would be appreciated.
error raised:
'' should equal 'xakep'
it means the answer that you will get should match to the desired output
print the url as your first step, so you can know for which test case it's failing
some python test cases
Test.describe("Basic tests") Test.assert_equals(domain_name("http://github.com/carbonfive/raygun"), "github") Test.assert_equals(domain_name("http://www.zombie-bites.com"), "zombie-bites") Test.assert_equals(domain_name("https://www.cnet.com"),"cnet")
Why don't I get any honor point when solving this one?!
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Thers is no error feedback.
This comment has been hidden.
There are a lot of edge cases missed by the test cases and missed by many of the successful submissions (including mine).
http
orhttps
(e.g. ftp://foo.example)Additionally, the name is a little misleading as this exercise is looking for the so-called "second level domain," not the full domain.
I recommend adding the following test cases:
Sorry for the re-post. I was trying to add this as a 'suggestion.'
This kata needs a better test suite. Most of the posted solutions would fail on ftp://sports.yahoo.com/somthing?unexpected=true
Often it occurs if regexp relies on particular protocol (http/https in current case).
what happened to the test cases? there is none
"www.xakep.ru", no prefix "http://" nor suffix ".com"
Submitted a CoffeeScript translation.
I really don't understand the appeal of CoffeeScript. It's a bit less tedious than Javascript but I prefer JS.
Good kata to practise regex !
Consider adding a testcase for something like "http://name.com/home.aspx". I feel like I passed too easily. :)
There's at least one solution that returns "u" for "http://example.com/u.pwned" and it's passed all the tests.
This comment has been hidden.
My code (in Python) seems to work on my machine (testing with the examples given in the instructions), but gives an error on the second test on the site. Unfortunately, I can't see the tests, so I don't know what's causing the error. (A 'Nonetype' object from my regex search.) I assume it means my regex expression isn't working quite right. Are there any symbols besides alphanumeric and hyphen allowed in the domain name?
Hmm... wasn't a problem with the regexp after all. Rather with using urlparse...
Javascript translation submitted: example test cases, lots of random test and also fixes the missing language in the current description.
It would be nice to have some pre-set tests to start with.
The kata can be cheated as it has only dotcom domains in check cases. Please add new tests so that it cannot be so easily cheated.
This comment has been hidden.
This comment has been hidden.
I tried the regexp method at first, but I'm still not good enough at it. Finally did it using the string manipulation.
Rubular is a good site to test regexp.
Your quick review really helps newbie to learn related material. Thank you.
The tests for subdomains should be included and should expect results for things like 'gmail.google.com' and 'a.b.c.gmail.google.com'.
Also agree with earlier comments that the expected solutions should include the TLD, so google.com in both cases not google.
Agree. Also tests for .co.uk extension types.
I made the ugliest solution ever and now I want to hide it :(
I'm partly in agreement with kerryb.
The domain name of "http://www.github.com/foo" is github.com or www.github.com, likewise the domain name of www.healthcare.gov is certainly not healthcare, it's healthcare.gov or www.healthcare.gov.
The description is misleading. The domain name of "http://www.github.com/foo" is "www.github.com", not "github".
yes, and sftp://username@alpha.beta.domain.com:80/a/b/c/?abc#xyz has alpha.beta.domain.com as a domain. This kata is kind of lame.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This is still the same code.
Looks like the comments strip out greater/less than symbols. Here's the full function that's working locally for me (I think!): http://pastebin.com/t0czVp7V
Apologies, I was returning a string instead of just the matched variable. All's good.
Yeah, cbean, that's a bug that I also came across -- it strips out anything that looks like an XML tag. That sucks, because assigning matched groups to variables is one of my favorite Ruby regex features!
Up vote if you think this kata should have its last test case removed. So that subdomains are never expected to be returned as the domain. Instead other subdomains just wouldn't factor into the kata.
This kata is broken. The last test should produce google, not gmail...
It looks like the kata only checks for www and naken domains, all other subdomains are treated as the actual domain. It calls it out in the description but its still kind of odd.
The kata tests for naked and www sub-domains but not other sub domains such as beta or www2. I'm going to update the description so that it indicates that only these two scenarios need to be handled.