Skip to content

Commit

Permalink
bug-1906021: strip whitespace from Android_CPU_ABI2 and other string …
Browse files Browse the repository at this point in the history
…fields (#6824)

This changes the CopyFromRawCrashRule to strip the right side of string
field values. I haven't seen anything in crash reports so far where
whitespace at the end of a crash annotation value is significant so I
think this is safe.

If it turns out not to be safe, we can extend CopyFromRawCrashRule to
look at a "transforms" field to glean how it should transform the value
after copying it. This would be helpful for the increasing number of
fields that are comma or semi-colon delimited, too.
  • Loading branch information
willkg authored Dec 3, 2024
1 parent 2113ced commit 8980ee7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion socorro/processor/rules/mozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ def action(self, raw_crash, dumps, processed_crash, tmpdir, status):
status.add_note(f"{annotation} has a non-float value")

elif copy_item.type_ == "string":
processed_crash[copy_item.key] = value
# NOTE(willkg): In 1906021, I noticed that Android_CPU_ABI2 has
# whitespace at the end. I looked at all the string values and I
# couldn't see any cases where whitespace at the end of a string value
# was meaningful, so we strip the whitespace at the end now. If we need
# it, we could add a "transform" field to the schema to dictate which
# transforms to apply after extracting the value. That would be nice for
# splitting on "," and other things, too.
processed_crash[copy_item.key] = value.rstrip()

elif copy_item.type_ == "object":
# If it's a string, then assume it's json-encoded and decode it
Expand Down
9 changes: 9 additions & 0 deletions socorro/tests/processor/rules/test_mozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,15 @@ def test_string(self, tmp_path):
assert processed_crash == {copy_item.key: "some string"}
assert status.notes == []

raw_crash = {copy_item.annotation: "some string with spaces\r\n "}
dumps = {}
processed_crash = {}
status = Status()
rule.act(raw_crash, dumps, processed_crash, str(tmp_path), status)

assert processed_crash == {copy_item.key: "some string with spaces"}
assert status.notes == []

def test_object(self, tmp_path):
rule = CopyFromRawCrashRule(schema=SCHEMA_WITH_ALL_TYPES)
copy_item = self.get_copy_item(rule, "ComplexStructure")
Expand Down

0 comments on commit 8980ee7

Please sign in to comment.