Skip to content

Commit e1a7b3d

Browse files
authored
Merge pull request #280 from j0k3r/fix/kep-empty-site-config-value
Ensure empty value from `site_config` are kept
2 parents 526c18f + 85634a8 commit e1a7b3d

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/SiteConfig/ConfigBuilder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ public function mergeConfig(SiteConfig $currentConfig, SiteConfig $newConfig)
320320
}
321321
}
322322

323+
// merge http_header array from currentConfig into newConfig
324+
// because final values override former values in case of named keys
325+
$currentConfig->http_header = array_merge($newConfig->http_header, $currentConfig->http_header);
326+
323327
// Complex solution to ensure find_string & replace_string aren't duplicated when merging config multiple times
324328
// We can't perform an array_unique on these values mostly because replace_string can have same values, example:
325329
// find_string: <amp-img
@@ -328,10 +332,7 @@ public function mergeConfig(SiteConfig $currentConfig, SiteConfig $newConfig)
328332
// replace_string: <img
329333
// To fix that issue, we combine find & replace as key & value in one array, we merge them and then rebuild find & replace string in the current config
330334

331-
// merge http_header array from currentConfig into newConfig
332-
// because final values override former values in case of named keys
333-
$currentConfig->http_header = array_merge($newConfig->http_header, $currentConfig->http_header);
334-
335+
// in case of bad configuration
335336
if (\count($currentConfig->find_string) !== \count($currentConfig->replace_string)) {
336337
return $currentConfig;
337338
}
@@ -378,7 +379,7 @@ public function parseLines(array $lines)
378379

379380
$val = trim($command[1]);
380381
$command = trim($command[0]);
381-
if ('' === $command || '' === $val) {
382+
if ('' === $command) {
382383
continue;
383384
}
384385

tests/GrabyFunctionalTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,36 @@ public function testCookie(): void
340340
// if the cookie wasn't taking into account, it'll be "NPR Choice page"
341341
$this->assertSame('Michael Flynn\'s Contradictory Line On Russia', $res['title']);
342342
}
343+
344+
public function testSaveXmlUnknownEncoding(): void
345+
{
346+
$graby = new Graby([
347+
'debug' => true,
348+
'extractor' => [
349+
'config_builder' => [
350+
'site_config' => [__DIR__ . '/fixtures/site_config'],
351+
],
352+
],
353+
]);
354+
$res = $graby->fetchContent('http://motherjones.com/politics/2012/02/mac-mcclelland-free-online-shipping-warehouses-labor');
355+
356+
$this->assertCount(11, $res);
357+
$this->assertSame(200, $res['status']);
358+
}
359+
360+
public function testWithEmptyReplaceString(): void
361+
{
362+
$graby = new Graby([
363+
'debug' => true,
364+
'extractor' => [
365+
'config_builder' => [
366+
'site_config' => [__DIR__ . '/fixtures/site_config'],
367+
],
368+
],
369+
]);
370+
$res = $graby->fetchContent('https://www.presseportal.de/pm/103258/2930232');
371+
372+
$this->assertCount(11, $res);
373+
$this->assertSame(200, $res['status']);
374+
}
343375
}

0 commit comments

Comments
 (0)