Skip to content

Commit

Permalink
add concatenation strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
mokhosh committed Nov 1, 2024
1 parent bf19f4a commit 2f9e428
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Strategies/Text/Concatenation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Mokhosh\Muddle\Strategies\Text;

use Mokhosh\Muddle\Contracts\TextStrategy;

class Concatenation implements TextStrategy
{
public function muddle(string $string): string
{
$concatenated = implode("'+'", str_split($string));

return "<script>document.write('".$concatenated."');</script>";
}

public function unmuddle(string $string): string
{
return str_replace(["<script>document.write('", "');</script>", "'", '+'], '', $string);
}
}
10 changes: 10 additions & 0 deletions tests/Strategies/Text/ConcatenationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

use Mokhosh\Muddle\Strategies\Text\Concatenation;

it('muddles text', function () {
expect($muddled = (new Concatenation)->muddle('[email protected]'))
->toBe("<script>document.write('t'+'e'+'s'+'t'+'@'+'e'+'x'+'a'+'m'+'p'+'l'+'e'+'.'+'c'+'o'+'m');</script>")
->and((new Concatenation)->unmuddle($muddled))
->toBe('[email protected]');
});

0 comments on commit 2f9e428

Please sign in to comment.