| 1 |
= String Expansion |
| 2 |
|
| 3 |
String expansion is a feature that allows strings to dynamically |
| 4 |
define their value at run time. For historical reasons, these string |
| 5 |
expansions are called "xlats". |
| 6 |
|
| 7 |
String expansion is performed via the following syntax: |
| 8 |
|
| 9 |
`%{...}` |
| 10 |
|
| 11 |
Where the `%{` signals the start of a dynamic expansion, and `}` |
| 12 |
signals the end of the dynamic expansion. The contents of the |
| 13 |
expansion can be many things: |
| 14 |
|
| 15 |
.String Expansions |
| 16 |
[options="header"] |
| 17 |
|===== |
| 18 |
| Keyword | Description |
| 19 |
| xref:xlat/attribute.adoc[attributes] | Expand the value of a named attribute. |
| 20 |
| xref:xlat/character.adoc[single character] | Single character expansions. |
| 21 |
| xref:xlat/module.adoc[modules] | Pass a string to a module such as `sql`. |
| 22 |
| xref:xlat/alternation.adoc[condition] | Conditionally expand a string. |
| 23 |
| xref:xlat/builtin.adoc[built-in expansions] | Such as string length, tolower, etc... |
| 24 |
|===== |
| 25 |
|
| 26 |
This feature is used to create policies which refer to concepts rather |
| 27 |
than to specific values. For example, a policy can be created that |
| 28 |
refers to the User-Name in a request, via: |
| 29 |
|
| 30 |
`%{User-Name}` |
| 31 |
|
| 32 |
This string expansion is done only for double-quoted strings and for |
| 33 |
the back-tick operator. |
| 34 |
|
| 35 |
== Caveats |
| 36 |
|
| 37 |
Unlike other languages, there is no way to define new variables. All |
| 38 |
of the string expansions must refer to attributes that already exist, |
| 39 |
or to modules that will return a string value. |
| 40 |
|
| 41 |
== Character Escaping |
| 42 |
|
| 43 |
Some characters need to be escaped within a dynamically expanded |
| 44 |
string `%{...}`. The `%` character is used for variable expansion, so a |
| 45 |
literal `%` character can be created by using `%%`. |
| 46 |
|
| 47 |
Other than within a dynamically expanded string, very little |
| 48 |
character escaping is needed. The rules of the enclosing string context |
| 49 |
determine whether or not a space or " character needs to be escaped. |
| 50 |
|
| 51 |
.Example |
| 52 |
|
| 53 |
`Reply-Message := "%{User-Name} with a literal %%` |
| 54 |
|
| 55 |
// Copyright (C) 2020 Network RADIUS SAS. Licenced under CC-by-NC 4.0. |
| 56 |
// Development of this documentation was sponsored by Network RADIUS SAS. |