Skip to content

Commit dddfae3

Browse files
authored
ref(pii): Use external utf16string crate (#807)
The relay-wstring crate has been split off to the utf16string crate, this switches our code over.
1 parent 7460f83 commit dddfae3

File tree

9 files changed

+25
-1353
lines changed

9 files changed

+25
-1353
lines changed

Cargo.lock

+10-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

relay-general/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pest_derive = "2.1.0"
2727
regex = "1.3.9"
2828
relay-common = { path = "../relay-common" }
2929
relay-general-derive = { path = "derive" }
30-
relay-wstring = { path = "../relay-wstring" }
3130
schemars = { version = "0.8.0-alpha-4", features = ["uuid", "chrono"], optional = true }
3231
scroll = "0.9.0"
3332
serde = { version = "1.0.114", features = ["derive"] }
@@ -37,6 +36,7 @@ sha-1 = "0.8.1"
3736
smallvec = { version = "1.4.0", features = ["serde"] }
3837
uaparser = { version = "0.3.3", optional = true }
3938
url = "2.1.1"
39+
utf16string = "0.2.0"
4040
uuid = { version = "0.8.1", features = ["v4", "serde"] }
4141

4242
[dev-dependencies]

relay-general/src/pii/attachments.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use std::iter::FusedIterator;
44
use regex::bytes::RegexBuilder as BytesRegexBuilder;
55
use regex::{Match, Regex};
66
use smallvec::SmallVec;
7-
8-
use relay_wstring::WStr;
7+
use utf16string::{LittleEndian, WStr};
98

109
use crate::pii::compiledconfig::RuleRef;
1110
use crate::pii::regexes::{get_regex_for_rule_type, ReplaceBehavior};
@@ -106,7 +105,11 @@ fn apply_regex_to_utf16le_bytes(
106105
}
107106

108107
/// Extract the matching encoded slice from the encoded string.
109-
fn get_wstr_match<'a>(all_text: &str, re_match: Match, all_encoded: &'a mut WStr) -> &'a mut WStr {
108+
fn get_wstr_match<'a>(
109+
all_text: &str,
110+
re_match: Match,
111+
all_encoded: &'a mut WStr<LittleEndian>,
112+
) -> &'a mut WStr<LittleEndian> {
110113
let mut encoded_start = 0;
111114
let mut encoded_end = all_encoded.len();
112115

@@ -172,7 +175,7 @@ trait StringMods: AsRef<[u8]> {
172175
}
173176
}
174177

175-
impl StringMods for WStr {
178+
impl StringMods for WStr<LittleEndian> {
176179
fn fill_content(&mut self, fill_char: char) {
177180
// If fill_char is too wide, fill_char.encode_utf16() will panic, fulfilling the
178181
// trait's contract that we must panic if fill_char is too wide.
@@ -325,7 +328,7 @@ impl<'a> FusedIterator for WStrSegmentIter<'a> {}
325328
/// longer match.
326329
struct WStrSegment<'a> {
327330
/// The raw bytes of this segment.
328-
encoded: &'a mut WStr,
331+
encoded: &'a mut WStr<LittleEndian>,
329332
/// The decoded string of this segment.
330333
decoded: String,
331334
}
@@ -469,7 +472,11 @@ impl<'a> PiiAttachmentsProcessor<'a> {
469472
}
470473

471474
/// Scrub a filepath, preserving the basename.
472-
pub fn scrub_utf16_filepath(&self, path: &mut WStr, state: &ProcessingState<'_>) -> bool {
475+
pub fn scrub_utf16_filepath(
476+
&self,
477+
path: &mut WStr<LittleEndian>,
478+
state: &ProcessingState<'_>,
479+
) -> bool {
473480
let index =
474481
path.char_indices().rev().find_map(
475482
|(i, c)| {

relay-general/src/pii/minidumps.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use minidump::{
1515
};
1616
use num_traits::FromPrimitive;
1717
use scroll::Endian;
18-
19-
use relay_wstring::{Utf16Error, WStr};
18+
use utf16string::{Utf16Error, WStr};
2019

2120
use crate::pii::{PiiAttachmentsProcessor, ScrubEncodings};
2221
use crate::processor::{FieldAttrs, Pii, ValueType};

relay-wstring/Cargo.toml

-10
This file was deleted.

0 commit comments

Comments
 (0)