Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
vendor/*
composer.lock
composer.phar
Expand Down
14 changes: 11 additions & 3 deletions source/robotstxtparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ class RobotsTxtParser

// robots.txt file content
private $content = '';

/**
* @var array
*/
private $regExpPatternReplace;

/**
* Constructor
*
* @param string $content - file content
* @param string $encoding - encoding
*/
public function __construct($content, $encoding = self::DEFAULT_ENCODING)
public function __construct($content, $encoding = self::DEFAULT_ENCODING, array $regExpPatternReplace = array())

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would like to pass in your own replaces, I guess it would make sense to merge our expected replaces with the user-ones, or at least pass the default ones by default:

Suggested change
public function __construct($content, $encoding = self::DEFAULT_ENCODING, array $regExpPatternReplace = array())
public function __construct($content, $encoding = self::DEFAULT_ENCODING, array $regExpPatternReplace = array('@' => '\@'))

{
// convert encoding
$encoding = !empty($encoding) ? $encoding : mb_detect_encoding($content);
Expand All @@ -104,6 +108,10 @@ public function __construct($content, $encoding = self::DEFAULT_ENCODING)

// parse rules - default state
$this->prepareRules();

$this->regExpPatternReplace = empty($regExpPatternReplace)
? array('@' => '\@')

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you would want to replace it but not merge? Could you please provide a test for this case?

: $regExpPatternReplace;
}

/**
Expand Down Expand Up @@ -771,7 +779,7 @@ private function checkBasicRule($rule, $path)
{
$rule = $this->prepareRegexRule($this->encode_url($rule));
// change @ to \@
$escaped = strtr($rule, array('@' => '\@'));
$escaped = strtr($rule, $this->regExpPatternReplace);
// match result
if (preg_match('@' . $escaped . '@', $path)) {
$this->log[] = 'Rule match: Path';
Expand Down