Skip to content

TXT records without quotation marks ignore content after first whitespace #116

@tquensen

Description

@tquensen

For a TXT record like example.org. TXT 300 v=spf1 mx include:spf.example.com -all the parser ignores the content after the first space.

TXT records are allowed to have multiple "character strings" so this behaviour is valid

I replaced the fromText method to resolve the issue. This also fixes content with multiple quoted strings, like "foo bar" "foo baz"

public function fromText(string $text): void
			{
				$string = new StringIterator($text);
				$txt = new StringIterator();

				while ($string->valid()) {
					if ($string->is(static::WHITESPACE)) {
						$string->next();
						continue;
					}

					if ($string->is(Tokens::DOUBLE_QUOTES)) {
						self::handleTxt($string, $txt);
						$string->next();
						$txt->append(' ');
						continue;
					}

					static::handleContiguousString($string, $txt);
					$string->next();
					$txt->append(' ');
				}

				$this->setText(trim((string) $txt), true);
			}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions