Resolve self depreciation

This commit is contained in:
Yassine Guedidi 2023-08-10 00:37:25 +01:00
parent 1ce5164e70
commit 8ef6a14652
6 changed files with 22 additions and 7 deletions

View file

@ -46,11 +46,15 @@ class UpdatePicturesPathCommand extends Command
$io->text('Retrieve existing entries'); $io->text('Retrieve existing entries');
$i = 1; $i = 1;
foreach ($query->toIterable() as $entry) { foreach ($query->toIterable() as $entry) {
$content = str_replace($oldUrl, $this->wallabagUrl, $entry->getContent()); $content = $entry->getContent();
$entry->setContent($content); if (null !== $content) {
$entry->setContent(str_replace($oldUrl, $this->wallabagUrl, $content));
}
$previewPicture = str_replace($oldUrl, $this->wallabagUrl, $entry->getPreviewPicture()); $previewPicture = $entry->getPreviewPicture();
$entry->setPreviewPicture($previewPicture); if (null !== $previewPicture) {
$entry->setPreviewPicture(str_replace($oldUrl, $this->wallabagUrl, $previewPicture));
}
if (0 === ($i % 20)) { if (0 === ($i % 20)) {
$this->entityManager->flush(); $this->entityManager->flush();

View file

@ -518,7 +518,7 @@ class EntryController extends AbstractController
); );
// don't redirect user to the deleted entry (check that the referer doesn't end with the same url) // don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
$prev = $request->getSession()->get('prevUrl'); $prev = $request->getSession()->get('prevUrl', '');
$to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null); $to = (1 !== preg_match('#' . $url . '$#i', $prev) ? $prev : null);
$redirectUrl = $this->redirectHelper->to($to); $redirectUrl = $this->redirectHelper->to($to);

View file

@ -45,7 +45,7 @@ class TagController extends AbstractController
$form = $this->createForm(NewTagType::class, new Tag()); $form = $this->createForm(NewTagType::class, new Tag());
$form->handleRequest($request); $form->handleRequest($request);
$tags = $form->get('label')->getData(); $tags = $form->get('label')->getData() ?? '';
$tagsExploded = explode(',', $tags); $tagsExploded = explode(',', $tags);
// avoid too much tag to be added // avoid too much tag to be added

View file

@ -94,7 +94,7 @@ class EntryFilterType extends AbstractType
->add('domainName', TextFilterType::class, [ ->add('domainName', TextFilterType::class, [
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
$value = $values['value']; $value = $values['value'];
if (\strlen($value) <= 2 || empty($value)) { if (empty($value) || \strlen($value) <= 2) {
return false; return false;
} }
$expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%'))); $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->lower($filterQuery->getExpr()->literal('%' . $value . '%')));

View file

@ -58,11 +58,19 @@ class WallabagExtension extends AbstractExtension implements GlobalsInterface
public function removeWww($url) public function removeWww($url)
{ {
if (!\is_string($url)) {
return $url;
}
return preg_replace('/^www\./i', '', $url); return preg_replace('/^www\./i', '', $url);
} }
public function removeScheme($url) public function removeScheme($url)
{ {
if (!\is_string($url)) {
return $url;
}
return preg_replace('#^https?://#i', '', $url); return preg_replace('#^https?://#i', '', $url);
} }

View file

@ -59,6 +59,7 @@ class WallabagExtensionTest extends TestCase
$this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeScheme('lemonde.fr'));
$this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com')); $this->assertSame('gist.github.com', $extension->removeScheme('gist.github.com'));
$this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com')); $this->assertSame('gist.github.com', $extension->removeScheme('https://gist.github.com'));
$this->assertSame('gist.github.com', $extension->removeScheme('http://gist.github.com'));
} }
public function testRemoveSchemeAndWww() public function testRemoveSchemeAndWww()
@ -82,8 +83,10 @@ class WallabagExtensionTest extends TestCase
$extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, ''); $extension = new WallabagExtension($entryRepository, $tagRepository, $tokenStorage, 0, $translator, '');
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('www.lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://www.lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('http://lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr')); $this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://www.lemonde.fr'));
$this->assertSame('lemonde.fr', $extension->removeSchemeAndWww('https://lemonde.fr'));
$this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com')); $this->assertSame('gist.github.com', $extension->removeSchemeAndWww('https://gist.github.com'));
$this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com')); $this->assertSame('ftp://gist.github.com', $extension->removeSchemeAndWww('ftp://gist.github.com'));
} }