Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/roundcube/roundcubemail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2022-05-08 11:43:33 +0300
committerAleksander Machniak <alec@alec.pl>2022-05-08 11:43:33 +0300
commitee04d8571f0783b74af7093704b5c1371c255572 (patch)
treec9d7eeae15cbda0e8ee2312948e6fc81ff34ebc0
parent720ba6f7a0a5ef398dfec571764ddbef37e5c1a1 (diff)
Fix so links (e.g. www.some.page or http://some.page) are not considered mispellings (#8527)
-rw-r--r--CHANGELOG.md1
-rw-r--r--program/lib/Roundcube/rcube_spellchecker.php9
-rw-r--r--tests/Framework/SpellcheckerEnchant.php14
-rw-r--r--tests/Framework/SpellcheckerPspell.php14
4 files changed, 38 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 775319227..83fbe1377 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,7 @@
- Fix bug where DSN flag state wasn't stored with a draft (#8371)
- Fix broken encoding of HTML content encapsulated in a RTF attachment (#8444)
- Fix problem with aria-hidden=true on toolbar menus in the Elastic skin (#8517)
+- Fix so links (e.g. www.some.page or http://some.page) are not considered mispellings (#8527)
## Release 1.6-beta
diff --git a/program/lib/Roundcube/rcube_spellchecker.php b/program/lib/Roundcube/rcube_spellchecker.php
index 4c6e236ad..992345030 100644
--- a/program/lib/Roundcube/rcube_spellchecker.php
+++ b/program/lib/Roundcube/rcube_spellchecker.php
@@ -138,6 +138,15 @@ class rcube_spellchecker
$this->content = $text;
}
+ // ignore links (#8527)
+ $callback = function ($matches) {
+ // replace the link with a dummy string that has the same length
+ // we can't just remove the link
+ return str_repeat(' ', strlen($matches[0]));
+ };
+
+ $this->content = preg_replace_callback('~(^|\s)(www.\S+|[a-z]+://\S+)~', $callback, $this->content);
+
if ($this->backend) {
$this->matches = $this->backend->check($this->content);
}
diff --git a/tests/Framework/SpellcheckerEnchant.php b/tests/Framework/SpellcheckerEnchant.php
index 04375b57b..47a188f13 100644
--- a/tests/Framework/SpellcheckerEnchant.php
+++ b/tests/Framework/SpellcheckerEnchant.php
@@ -70,6 +70,20 @@ class Framework_SpellcheckerEnchant extends PHPUnit\Framework\TestCase
'|^<\?xml version="1.0" encoding="UTF-8"\?><spellresult charschecked="3"><c o="0" l="3">([a-zA-Z\t]+)</c></spellresult>$|',
$object->get_xml()
);
+
+ // Test that links are ignored (#8527)
+ $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
+ . '<p><a href="http://www.redacted.com">www.redacted.com</a></div></body></html>';
+
+ $this->assertTrue($object->check($html, true));
+
+ $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
+ . '<p><a href="http://www.redacted.com">http://www.redacted.com</a></div></body></html>';
+
+ $this->assertTrue($object->check($html, true));
+
+ $this->assertTrue($object->check('one http://www.redacted.com'));
+ $this->assertTrue($object->check('one www.redacted.com'));
}
/**
diff --git a/tests/Framework/SpellcheckerPspell.php b/tests/Framework/SpellcheckerPspell.php
index b7e385eac..e10e160b6 100644
--- a/tests/Framework/SpellcheckerPspell.php
+++ b/tests/Framework/SpellcheckerPspell.php
@@ -70,6 +70,20 @@ class Framework_SpellcheckerPspell extends PHPUnit\Framework\TestCase
'|^<\?xml version="1.0" encoding="UTF-8"\?><spellresult charschecked="3"><c o="0" l="3">([a-zA-Z\t]+)</c></spellresult>$|',
$object->get_xml()
);
+
+ // Test that links are ignored (#8527)
+ $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
+ . '<p><a href="http://www.redacted.com">www.redacted.com</a></div></body></html>';
+
+ $this->assertTrue($object->check($html, true));
+
+ $html = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>'
+ . '<p><a href="http://www.redacted.com">http://www.redacted.com</a></div></body></html>';
+
+ $this->assertTrue($object->check($html, true));
+
+ $this->assertTrue($object->check('one http://www.redacted.com'));
+ $this->assertTrue($object->check('one www.redacted.com'));
}
/**