The Linux Page

BIND parser supports double quoted string with escaped characters

Address book, BIND and is an electronic address fast.

BIND Quoted String Support

I noticed a lack of description of the BIND support for strings in their documentation.

Unfortunately, there are many flags in their parser so truth be told, they support many different cases. First of all, some of the files that they parse do not support quoted strings at all. So I wanted to document what is supported:

No Strings

As I just mentioned, some files do not support strings at all. In that case, the double quote (") character is likely to be viewed as a character on its own.

Also "master" defines the double quote character as a special character.

Simple Strings

Also escaping is supported, the parser has a flag to know whether to accept the backslash character or not. If not, I call that a simple string. The first quote is the opening quote and the next quote is the closing quote, no matter what.

For example, the following string cleanly ends with a backslash (\).

option = "simple string \";

Note that where what is supported is a tad bit complicated to determine so I don't have the answer. The fact is that you shouldn't be too surprised if you have such a simple string appear in a setup file somewhere and there is backslash before the closing double quote (").

Normal Strings

I will call the last type of strings the Normal Strings.

These strings support escaping. Of course, the only two characters that require escaping is the double quote character (") and the backslash character (\) since all the other characters are anyway taken literaly when appearing in a string. So there is no need to escape anything other than a double quote (") or backslash (\).

See the Multi-line Strings below for one additional case where a backslash (\) can be used.

option = "normal \"strings\" support quoting\\";

Here we see that to add a backslash at the end of a normal string, you need to write two of them, otherwise the quote is going to be taken as part of the string and the data after that read as part of the string.

Multi-line Strings

Normal strings (Those that support escape) also support multi-line strings. This means you can write a backslash character (\) followed by a newline character and th string will continue on the next line.

The multi-line AND the escape features must both be turned on for this functionality to work.

multi_option = "this is a long\
string which continues\
on multiple lines";

In all other cases, a newline character within a string is considered an error in your configuration file.

Note that the newline character (\n) is kept in the string, however, the backslash characters (\) are always removed.

Single Quote Strings

Somehow these are not supported at all. Single quotes are viewed as apostrophes, I suppose. There is no special handling of the single quote character, so it can probably only appear in comments and strings.