Skip to content

Commit

Permalink
feat: use rfc 6868 escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
joostdebruijn committed May 16, 2024
1 parent cb37b03 commit 2d5bf6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Properties/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public function getValue(): string
}

$replacements = [
'\\' => '\\\\',
'"' => '\\"',
// RFC 5545
'\\' => '\\\\',
',' => '\\,',
';' => '\\;',
"\n" => '\\n',
// RFC 6868
'^' => '^^',
'"' => '^\'',
PHP_EOL => '^n',
];

return str_replace(array_keys($replacements), $replacements, $value);
Expand Down
11 changes: 8 additions & 3 deletions tests/Properties/ParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
);

assertEquals(
'a quote \\" ',
'a quote ^\' ',
(new Parameter('', 'a quote " '))->getValue()
);

Expand All @@ -28,8 +28,13 @@
);

assertEquals(
'a return \\\n ',
(new Parameter('', 'a return \n '))->getValue()
'a return ^n ',
(new Parameter('', 'a return '.PHP_EOL.' '))->getValue()
);

assertEquals(
'a circumflex accent ^^ ',
(new Parameter('', 'a circumflex accent ^ '))->getValue()
);
});

Expand Down

0 comments on commit 2d5bf6e

Please sign in to comment.