Skip to content

Commit

Permalink
Merge pull request #131 from joostdebruijn/joost/feat-follow-rfc6868
Browse files Browse the repository at this point in the history
feat: use rfc 6868 escaping
  • Loading branch information
freekmurze authored May 16, 2024
2 parents cbc9862 + 8d5fc2b commit 00097f6
Show file tree
Hide file tree
Showing 2 changed files with 19 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
16 changes: 13 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 Expand Up @@ -58,6 +63,11 @@
'a return \n ',
(new Parameter('', 'a return \n ', true))->getValue()
);

assertEquals(
'a return ^ ',
(new Parameter('', 'a return ^ ', true))->getValue()
);
});

test('it can format a boolean', function () {
Expand Down

0 comments on commit 00097f6

Please sign in to comment.