Skip to content

Commit

Permalink
fix: value normalization (via value::normalize() handles escape seq…
Browse files Browse the repository at this point in the history
…uences. (#331)

The latter ones are `\n`, `\t` and `\b` which are the only supported
ones in values of git-config files.
  • Loading branch information
Byron committed Jul 11, 2022
1 parent cf3bf4a commit f911707
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions git-config/src/value/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ use std::borrow::Cow;

use bstr::{BStr, BString, ByteSlice};

/// Removes quotes, if any, from the provided inputs. This assumes the input
/// contains a even number of unescaped quotes, and will unescape escaped
/// quotes. The return values should be safe for value interpretation.
/// Removes quotes, if any, from the provided inputs, and transforms
/// the 3 escape sequences `\n`, `\t` and `\b` into newline and tab
/// respectively, while `\b` will remove the previous character.
///
/// It assumes the input contains a even number of unescaped quotes,
/// and will unescape escaped quotes and everything else (even though the latter
/// would have been rejected in the parsing stage).
///
/// The return values should be safe for value interpretation.
///
/// This has optimizations for fully-quoted values, where the returned value
/// will be a borrowed reference if the only mutation necessary is to unquote
Expand Down

0 comments on commit f911707

Please sign in to comment.