-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not log PII in Debug implementations
Related to #1707 but does not resolve it. Still need a solution to redact headers as needed.
- Loading branch information
Showing
12 changed files
with
185 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
//! Formatting helpers. | ||
|
||
use std::borrow::Cow; | ||
|
||
/// Converts ASCII characters in `value` to lowercase if required; otherwise, returns the original slice. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Returns the original slice: | ||
/// | ||
/// ``` | ||
/// # use std::borrow::Cow; | ||
/// # use typespec_client_core::fmt::to_ascii_lowercase; | ||
/// let actual = to_ascii_lowercase("hello, world!"); | ||
/// assert!(matches!(actual, Cow::Borrowed("hello, world!"))); | ||
/// ``` | ||
/// | ||
/// Returns a clone converted to lowercase ASCII character. | ||
/// | ||
/// ``` | ||
/// # use std::borrow::Cow; | ||
/// # use typespec_client_core::fmt::to_ascii_lowercase; | ||
/// let actual = to_ascii_lowercase("hello, World!"); | ||
/// assert!(matches!( | ||
/// actual, | ||
/// Cow::Owned(expected) if expected == "hello, world!" | ||
/// )); | ||
/// ``` | ||
pub fn to_ascii_lowercase<'a>(value: &'a str) -> Cow<'a, str> { | ||
for (i, c) in value.chars().enumerate() { | ||
if c.is_ascii_uppercase() { | ||
let mut s = value.to_owned(); | ||
s[i..].make_ascii_lowercase(); | ||
|
||
return Cow::Owned(s); | ||
} | ||
} | ||
|
||
Cow::Borrowed(value) | ||
} | ||
|
||
#[test] | ||
fn test_to_ascii_lowercase() { | ||
let actual = to_ascii_lowercase("hello, 🌎!"); | ||
assert!(matches!(actual, Cow::Borrowed("hello, 🌎!"))); | ||
|
||
let actual = to_ascii_lowercase("Hello, 🌎!"); | ||
assert!(matches!( | ||
actual, | ||
Cow::Owned(expected) if expected == "hello, 🌎!" | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters