New tool from curl creator – trurl – for URL parsing and manipulation
daniel.haxx.se
daniel.haxx.se
https://news.ycombinator.com/item?id=35419573 - 22 points, 2 comments
https://news.ycombinator.com/item?id=35426050 - 5 points, 0 comments
Apparently, it requires curl 7.81 to compile, but I'm on ubuntu 20 (7.6x) and wanted to do a quick try, so this patch makes it work (trivially) by removing the couple of new symbols depending on that newer version. Just a quick hack to compile.
--- a/trurl.c
+++ b/trurl.c
@@ -362,11 +362,12 @@ static void get(struct option *op, CURLU *uh)
case CURLUE_NO_PORT:
case CURLUE_NO_QUERY:
case CURLUE_NO_FRAGMENT:
- case CURLUE_NO_ZONEID:
+ // would require 7.81
+ // case CURLUE_NO_ZONEID:
/\* silently ignore */
break;
default:
- fprintf(stderr, PROGNAME ": %s (%s)\n", curl_url_strerror(rc),
+ fprintf(stderr, PROGNAME ": %s (%s)\n", rc,
variables[i].name);
break;
}
@@ -589,8 +590,8 @@ static void singleurl(struct option *o,
CURLU_GUESS_SCHEME|CURLU_NON_SUPPORT_SCHEME);
if(rc) {
if(o->verify)
- errorf(ERROR_BADURL, "%s [%s]", curl_url_strerror(rc), url);
- warnf("%s [%s]", curl_url_strerror(rc), url);
+ errorf(ERROR_BADURL, "%s [%s]", rc, url);
+ warnf("%s [%s]", rc, url);
}
else {
if(o->redirect)Most of the tools assume opposite default (like xargs for example). Sure, you can specify a different order but why make life harder for no reason?
But you can put options wherever you want, they are identified by the leading '-' char.
> trurl is a tool in a similar spirit of tr but for URLs. Here, tr stands for translate or transpose.
> URLs are tricky to parse and there are numerous security problems in software because of this. trurl wants to help soften this problem by taking away the need for script and command line authors everywhere to re-invent the wheel over and over.
Or is it just that this is focused on command-line usage
I currently parse out this stuff using a flaky little bit of python I cooked up myself and it gives me no end of grief when scaled. So many awful edge cases.
The author wrote curl, so I know it's going to do what it says it does well.
That's why it's getting love. It's a rock star dev putting out open source code many of us will absolutely be using regularly.
Way classier than yet another "product" built on the OpenAI API that will be gone in a year.
For example, you want to apply a sequence of predefined normalization steps, such as removing the user part, converting http to https, etc etc. You put these steps in a file and then invoke trurl with that file and pointed at your url or urls. Very much like what you would do in sed, say. Possible?
> $ trurl --url https://example.com --set path=/abc/123 --set scheme=ftp --set host=foo.bar
> $ ftp://foo.bar/abc/123
tru-rul? tee-ru-rul?
“Have it compose a poem — a poem about a haircut! But lofty, noble, tragic, timeless, full of love, treachery, retribution, quiet heroism in the face of certain doom! Six lines, cleverly rhymed, and every word beginning with the letter S!!”
“Seduced, shaggy Samson snored.
She scissored short. Sorely shorn,
Soon shackled slave, Samson sighed,
Silently scheming,
Sightlessly seeking
Some savage, spectacular suicide.”
https://mwichary.medium.com/seduced-shaggy-samson-snored-725...
She sat with scissors, ready to snip,
Slicing strands of hair, curl by curl, clip by clip,
Shears shimmering, sharp as swords in sunlight,
Swiftly, skillfully, she shortened the sight,
Saddened by strands strewn on the floor,
She stood, serene, satisfied, the style was no more.
Clearly nowhere as good, and it couldn't get all the words to start with an 'S', even with a few attempts to correct it.
Still, some software should succeed someday, sans skipped S's. Substituting some synonyms, surely.