News for hackers. Stuff that matters.
Re:Potholes to avoid when migrating to IPv6 by GlitchMr on Monday December 31, 2018 @04:47AM (#18793851)
Don't manually parse those things. If your database provides a way to parse those (like PostgreSQL does), make use of it. Use what your programming language provides, and if it really doesn't provide the functionality to parse IPv6 addresses, use a library to do so.

For example, in Rust you can write this:

    use std::error::Error;
    use std::net::{AddrParseError, SocketAddr};
    
    fn parse_address(addr: &str) -> Result<SocketAddr, AddrParseError> {
        addr.parse()
            .or_else(|_| Ok(SocketAddr::new(addr.parse()?, 10443)))
    }
    
    fn main() -> Result<(), Box<dyn Error>> {
        let addresses = [
            "[2001:0db8:f00f::0553:1211:0088]:10444",
            "2001:0db8:f00f::0553:1211:0088",
        ];
        for address in &addresses {
            println!("{:?}", parse_address(address)?);
        }
        Ok(())
    }
This isn't specific to IPv6 by the way. It also applies to other standards like CSV (although I suppose with CSV it does vary, I saw so many broken CSV files that sometimes a custom implementation is the best way to go to parse those).
Re:Potholes to avoid when migrating to IPv6 by mavhc on Monday December 31, 2018 @07:26AM (#18794216)
The most stupid thing about CSV is it's entirely pointless, ASCII has codepoints for file, group, record and unit separators.
Re:Potholes to avoid when migrating to IPv6 by twic on Monday December 31, 2018 @07:58AM (#18794295)
Which you can't type on a keyboard, sensibly print on a terminal, or express with a symbolic escape (like '\n') in any language i know.

If history had gone differently, the separators would be useful for separating things in files, but it didn't.

Re:Potholes to avoid when migrating to IPv6 by JdeBP on Monday December 31, 2018 @08:12AM (#18794348)
I am sure I am not alone at chuckling at the idea that one cannot type FS, GS, RS, and US on a keyboard, clearly borne of GUI conventions and thinking. Some of us have been typing control characters on a keyboard for quite a number of years. This is what the [Control] key is for. (-:

FS enjoys quite significant use nowadays on terminal keyboards in the worlds of Unix and Linux, it being the usual special character mapped to SIGQUIT. GS and RS are similarly fairly mainstream commands in VIM/NeoVIM.

Re:Potholes to avoid when migrating to IPv6 by adwn on Monday December 31, 2018 @09:13AM (#18794542)
> I am sure I am not alone at chuckling at the idea [...]

You might want to hold back on your condescending laughter for a bit. Neither vim nor nano allow me to insert a control character by pressing Ctrl+key, so how am I supposed enter the FS character when editing a text file? Besides, there are other operating systems besides Unix and Linux (cough Windows cough).

Re:Potholes to avoid when migrating to IPv6 by jodoherty on Monday December 31, 2018 @09:23AM (#18794582)
Actually, VIM does support this. Type Ctrl+V in insert mode followed by whatever you want to insert (e.g. Ctrl+\ for the ASCII FS character). VIM will insert the literal value of the control code into the buffer.
Re:Potholes to avoid when migrating to IPv6 by adwn on Monday December 31, 2018 @10:56AM (#18795049)
Thanks! I had tried Ctrl+V followed by the character from the caret notation (e.g., "Ctrl+V \", instead of "Ctrl+V Ctrl+\"), and that hadn't worked.
Re:Potholes to avoid when migrating to IPv6 by JdeBP on Monday December 31, 2018 @09:49AM (#18794687)
The condescension here is supplied by you. Alas, it is based upon inaccuracy.

VIM/NeoVIM cannot stop you from entering control characters by pressing [Control] and a key. It is a function of one's terminal or terminal emulator that (aside from employing some fairly unconventional keyboard maps) does not get turned off.

You are confusing entering text with typing control characters on a keyboard. One types these control characters with VIM/NeoVIM all of the time. One of them, after all, is ESC, and the others are fairly common as I said. That the control characters are commands, even in insert mode, is a different matter. One such command is the SYN control character, typed on the keyboard of course with the [Control] key as [Control]-V, whose use demonstrates that in VIM/NeoVIM one most definitely can insert control characters as text.

The fact that you brought up nano is also somewhat risible. That has a large banner across the bottom of the screen telling you what control characters the editor responds to, which one uses the [Control] key to type on the keyboard. It's staring you right in the face. (FS is even one of the ones on the main menu.)

I'll let you discover the equally simple key chord that you can use with nano, which likewise does let you insert control characters as text with the [Control] key.

As for Windows, you might want to fire up a console and actually try pressing some [Control]-key chords. For best results, run a console program that follows much the same convention. In TCC, for example, Alt-255 is the literal-next-character convention. But even without such a program, SUB as an end of input indicator, typed on the keyboard as [Control]-Z, is a fairly easy demonstration; and an application-level convention that goes back a long way.

* https://jpsoft.com/help/editing.htm

Re:Potholes to avoid when migrating to IPv6 by dang on Monday December 31, 2018 @04:19PM (#18797103)
> The condescension here is supplied by you.

Please edit that sort of thing out of your comments here. The GP shouldn't have included that provocation, but there are a lot of provocations on the internet, and for good discussion here we all need to build a certain immunity. A perfectly good thread about control characters needn't be marred by ill will!

https://news.ycombinator.com/newsguidelines.html

Re:Potholes to avoid when migrating to IPv6 by twic on Wednesday January 02, 2019 @06:26AM (#18805529)
It's not even a particularly good thread about control characters :(.
Re:Potholes to avoid when migrating to IPv6 by jsjohnst on Monday December 31, 2018 @09:30AM (#18794613)
> Which you can't type on a keyboard

Your keyboard doesn’t have the following keys?

ctl-\, ctl-], ctl-^, and ctl-_

Re: “symbolic” escapes, sure, but there’s always:

\x1c, \x1d, \x1e, and \x1f

Not everything can be a single character, there’s only 26 of those in the English language.

Re:Potholes to avoid when migrating to IPv6 by ben0x539 on Monday December 31, 2018 @09:50AM (#18794694)
My system seems to terminate the program I'm typing into when I press Control-\. Also, with the default German kez^Hymap, I can't seem to type Control-^.
Re:Potholes to avoid when migrating to IPv6 by simcop2387 on Monday December 31, 2018 @10:12AM (#18794776)
Try Ctrl+V first, if it's not been bound to paste. No idea how a german layout affects things though.
Re:Potholes to avoid when migrating to IPv6 by cryptonector on Monday December 31, 2018 @01:02PM (#18795879)
You can type them! E.g., ctrl-^ is record separator.

  $ echo ^\^]^^^_|od -c
  0000000 034 035 036 037  \n
  0000005
So, ^\ is FS, ^] is GS, ^^ is RS, and ^_ is US.
Re:Potholes to avoid when migrating to IPv6 by loeg on Monday December 31, 2018 @08:02PM (#18798218)
It's probably worth remembering that these combinations are unintuitive and not readily printed on keyboards. Additionally, all text editors can render a CSV correctly; I doubt the same can be said for Unix control characters.

I suspect fewer than 1% of computer users has these memorized. For that matter, I suspect fewer than 1% of software developers or sysadmins have these memorized.

In contrast, the comma, tab, and return keys are easily located on any keyboard, and CSV delimiters are all so common as to be readily printable by any text editor.

Meanwhile, unix escape sequences don't solve the quoting / escape problem of representing strings containing the delimiters anyway.

Re:Potholes to avoid when migrating to IPv6 by icedchai on Monday December 31, 2018 @02:53PM (#18796563)
Good luck remembering what characters those are and viewing them in most terminals without a hex dump.

Remember that CSV is also for human consumption.

Re:Potholes to avoid when migrating to IPv6 by romeisendcoming on Monday December 31, 2018 @09:47AM (#18794674)
Come up with a convention and stick to it. Bracketed network/host, trailing port. Shoot anyone who does it any other way. Ignore case in network/host...and yes you need to be able to do this. Counting on some other system to do the right thing is silly.
Re:Potholes to avoid when migrating to IPv6 by ninkendo on Monday December 31, 2018 @03:03PM (#18796622)
> Shoot anyone who does it any other way.

> Counting on some other system to do the right thing is silly.

Do you see the contradiction in these statements?

Re:Potholes to avoid when migrating to IPv6 by romeisendcoming on Tuesday January 01, 2019 @08:47AM (#18800146)
Why yes, thank you. But without being morbidly explicit joining these phrases without context could put someone in jail...and that is what you did there. My point was to pick a convention and enforce it and (secondly) that using some agency ( I believe postgresql, various APIs, were mentioned throughout) is silly imho. People are going to use strings and parse them. Just make it the same format everywhere.