Skip to content

Commit e8084b4

Browse files
authored
Merge pull request #130 from Coderberg/2.x
Release 2.10.2
2 parents 20a24fd + ba6d0c8 commit e8084b4

36 files changed

+1597
-823
lines changed

composer.lock

Lines changed: 1395 additions & 661 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
locale: 'en'
88
app_locales: 'en|ru|nl|bg|hu'
99
images_directory: '%kernel.project_dir%/public/uploads/images'
10-
app_version: '2.10.1'
10+
app_version: '2.10.2'
1111

1212
services:
1313
# default configuration for services in *this* file

src/Service/User/PropertyService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function sanitizeHtml(Property $property, bool $isHtmlAllowed): Property
6868
if (!$isHtmlAllowed) {
6969
$property = $this->propertyTransformer->contentToPlainText($property);
7070
$property = $this->propertyTransformer->contentToHtml($property);
71+
} else {
72+
$property = $this->propertyTransformer->removeScriptsFromHtml($property);
7173
}
7274

7375
return $property;

src/Transformer/PropertyTransformer.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,25 @@ final class PropertyTransformer
1111
{
1212
public function contentToHtml(Property $property): Property
1313
{
14-
$htmlContent = HtmlHelper::text2Html($property->getPropertyDescription()->getContent());
15-
$property->setPropertyDescription(
16-
$property->getPropertyDescription()->setContent($htmlContent)
17-
);
18-
19-
return $property;
14+
return $this->transformContent($property, HtmlHelper::text2Html(...));
2015
}
2116

2217
public function contentToPlainText(Property $property): Property
2318
{
24-
$htmlContent = $property->getPropertyDescription()->getContent();
25-
$textContent = HtmlHelper::html2Text($htmlContent);
19+
return $this->transformContent($property, HtmlHelper::html2Text(...));
20+
}
21+
22+
public function removeScriptsFromHtml(Property $property): Property
23+
{
24+
return $this->transformContent($property, HtmlHelper::removeScriptsFromHtml(...));
25+
}
26+
27+
private function transformContent(Property $property, callable $transformFunction): Property
28+
{
29+
$content = $property->getPropertyDescription()->getContent();
30+
$transformedContent = \call_user_func($transformFunction, $content);
2631
$property->setPropertyDescription(
27-
$property->getPropertyDescription()->setContent($textContent)
32+
$property->getPropertyDescription()->setContent($transformedContent)
2833
);
2934

3035
return $property;

src/Utils/HtmlHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ public static function text2Html(string $text): string
1717
{
1818
return preg_replace("/\r\n|\r|\n/", '<br>', $text);
1919
}
20+
21+
public static function removeScriptsFromHtml(string $html): string
22+
{
23+
$sanitizedHtml = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $html);
24+
$sanitizedHtml = preg_replace('# on\w+="[^"]*"#i', '', (string) $sanitizedHtml);
25+
26+
return preg_replace("# on\w+='[^']*'#i", '', (string) $sanitizedHtml);
27+
}
2028
}

tests/Functional/Controller/Admin/CategoryControllerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Category;
88
use App\Tests\Helper\WebTestHelper;
99
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
10+
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
1112

1213
final class CategoryControllerTest extends WebTestCase
@@ -23,7 +24,7 @@ final class CategoryControllerTest extends WebTestCase
2324
public function testAdminNewCategory(): void
2425
{
2526
$client = $this->authAsAdmin($this);
26-
$crawler = $client->request('GET', '/en/admin/category/new');
27+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/category/new');
2728

2829
$form = $crawler->selectButton('Create category')->form([
2930
'category[name]' => self::NAME,
@@ -58,7 +59,7 @@ public function testAdminEditCategory(): void
5859
'slug' => self::SLUG,
5960
])->getId();
6061

61-
$crawler = $client->request('GET', '/en/admin/category/'.$category.'/edit');
62+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/category/'.$category.'/edit');
6263

6364
$form = $crawler->selectButton('Save changes')->form([
6465
'category[name]' => self::EDITED_NAME,
@@ -91,7 +92,7 @@ public function testAdminDeleteCategory(): void
9192
'slug' => self::SLUG,
9293
])->getId();
9394

94-
$crawler = $client->request('GET', '/en/admin/category');
95+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/category');
9596
$client->submit($crawler->filter('#delete-form-'.$category)->form());
9697
$this->assertSame(
9798
Response::HTTP_FOUND,

tests/Functional/Controller/Admin/CityControllerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace App\Tests\Functional\Controller\Admin;
66

77
use App\Entity\City;
8+
use Symfony\Component\HttpFoundation\Request;
89
use Symfony\Component\HttpFoundation\Response;
910

1011
final class CityControllerTest extends AbstractLocationControllerTest
@@ -14,7 +15,7 @@ final class CityControllerTest extends AbstractLocationControllerTest
1415
*/
1516
public function testAdminNewCity(): void
1617
{
17-
$crawler = $this->client->request('GET', '/en/admin/locations/city/new');
18+
$crawler = $this->client->request(Request::METHOD_GET, '/en/admin/locations/city/new');
1819

1920
$form = $crawler->selectButton('Create city')->form([
2021
'city[name]' => self::NAME,
@@ -52,7 +53,7 @@ public function testAdminEditCity(): void
5253
'slug' => self::SLUG,
5354
])->getId();
5455

55-
$crawler = $this->client->request('GET', '/en/admin/locations/city/'.$city.'/edit');
56+
$crawler = $this->client->request(Request::METHOD_GET, '/en/admin/locations/city/'.$city.'/edit');
5657

5758
$form = $crawler->selectButton('Save changes')->form([
5859
'city[name]' => self::EDITED_NAME,
@@ -88,7 +89,7 @@ public function testAdminDeleteCity(): void
8889
'slug' => self::SLUG,
8990
])->getId();
9091

91-
$crawler = $this->client->request('GET', '/en/admin/locations/city');
92+
$crawler = $this->client->request(Request::METHOD_GET, '/en/admin/locations/city');
9293
$this->client->submit($crawler->filter('#delete-form-'.$city)->form());
9394
$this->assertSame(
9495
Response::HTTP_FOUND,

tests/Functional/Controller/Admin/CurrencyControllerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Currency;
88
use App\Tests\Helper\WebTestHelper;
99
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
10+
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
1112

1213
final class CurrencyControllerTest extends WebTestCase
@@ -23,7 +24,7 @@ public function testAdminNewCurrency(): void
2324
{
2425
$client = $this->authAsAdmin($this);
2526

26-
$crawler = $client->request('GET', '/en/admin/currency/new');
27+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/currency/new');
2728

2829
$form = $crawler->selectButton('Create currency')->form([
2930
'currency[currency_title]' => self::CURRENCY,
@@ -57,7 +58,7 @@ public function testAdminEditCurrency(): void
5758
'code' => self::CURRENCY,
5859
])->getId();
5960

60-
$crawler = $client->request('GET', '/en/admin/currency/'.$currency.'/edit');
61+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/currency/'.$currency.'/edit');
6162

6263
$form = $crawler->selectButton('Save changes')->form([
6364
'currency[currency_title]' => self::EDITED,
@@ -91,7 +92,7 @@ public function testAdminDeleteCurrency(): void
9192
'code' => self::EDITED,
9293
])->getId();
9394

94-
$crawler = $client->request('GET', '/en/admin/currency');
95+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/currency');
9596
$client->submit($crawler->filter('#delete-form-'.$currency)->form());
9697
$this->assertSame(
9798
Response::HTTP_FOUND,

tests/Functional/Controller/Admin/DashboardControllerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\Tests\Helper\WebTestHelper;
88
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9+
use Symfony\Component\HttpFoundation\Request;
910

1011
final class DashboardControllerTest extends WebTestCase
1112
{
@@ -14,7 +15,7 @@ final class DashboardControllerTest extends WebTestCase
1415
public function testAdminDashboard(): void
1516
{
1617
$client = $this->authAsAdmin($this);
17-
$client->request('GET', '/en/admin');
18+
$client->request(Request::METHOD_GET, '/en/admin');
1819
$this->assertResponseIsSuccessful(sprintf('The %s public URL loads correctly.', '/admin'));
1920
}
2021
}

tests/Functional/Controller/Admin/DealTypeControllerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\DealType;
88
use App\Tests\Helper\WebTestHelper;
99
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
10+
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
1112

1213
final class DealTypeControllerTest extends WebTestCase
@@ -24,7 +25,7 @@ public function testAdminNewDealType(): void
2425
{
2526
$client = $this->authAsAdmin($this);
2627

27-
$crawler = $client->request('GET', '/en/admin/deal_type/new');
28+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/deal_type/new');
2829

2930
$form = $crawler->selectButton('Create deal type')->form([
3031
'deal_type[name]' => self::NAME,
@@ -59,7 +60,7 @@ public function testAdminEditDealType(): void
5960
'slug' => self::SLUG,
6061
])->getId();
6162

62-
$crawler = $client->request('GET', '/en/admin/deal_type/'.$dealType.'/edit');
63+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/deal_type/'.$dealType.'/edit');
6364

6465
$form = $crawler->selectButton('Save changes')->form([
6566
'deal_type[name]' => self::EDITED_NAME,
@@ -92,7 +93,7 @@ public function testAdminDeleteDealType(): void
9293
'slug' => self::SLUG,
9394
])->getId();
9495

95-
$crawler = $client->request('GET', '/en/admin/deal_type');
96+
$crawler = $client->request(Request::METHOD_GET, '/en/admin/deal_type');
9697
$client->submit($crawler->filter('#delete-form-'.$dealType)->form());
9798
$this->assertSame(
9899
Response::HTTP_FOUND,

0 commit comments

Comments
 (0)