Quantcast

[Tiki-devel] PCRE metacharacters in hotwords (RE: [Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[61559] trunk/lib/parser/parserlib.php)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Tiki-devel] PCRE metacharacters in hotwords (RE: [Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[61559] trunk/lib/parser/parserlib.php)

Cloutier, Philippe (RESSOURCE EXTERNE)
Hi,
r61559 fixes 2 issues which could happen when a hotword contained PCRE metacharacters:
1. If the resulting pattern was invalid, the result of parsing would be empty.
2. Hotwords would match text different from the hotword itself (for example, "I.O." would match "IGOR")

This fix causes each hotword to match only the word literally. I intend to backport to Tiki 12. The previous behavior of interpreting the hotword as a pattern was not documented. If someone intentionally used such patterns, please say so.

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]]
Envoyé : 7 mars 2017 16:33
À : [hidden email]
Objet : [Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[61559] trunk/lib/parser/parserlib.php

Revision: 61559
          http://sourceforge.net/p/tikiwiki/code/61559
Author:   chealer
Date:     2017-03-07 21:33:16 +0000 (Tue, 07 Mar 2017)
Log Message:
-----------
[FIX] replace_hotwords(): empty lines returned when some hotwords containing PCRE metacharacters are present
Escape all PCRE metacharacters rather than just slashes.
Was already present in 2006

Modified Paths:
--------------
    trunk/lib/parser/parserlib.php

Modified: trunk/lib/parser/parserlib.php
===================================================================
--- trunk/lib/parser/parserlib.php 2017-03-07 19:07:16 UTC (rev 61558)
+++ trunk/lib/parser/parserlib.php 2017-03-07 21:33:16 UTC (rev 61559)
@@ -1357,10 +1357,10 @@
  $sep = empty($sep)? " \n\t\r\,\;\(\)\.\:\[\]\{\}\!\?\"":"$sep";
  foreach ($words as $word => $url) {
  // \b is a word boundary, \s is a space char
- $pregword = preg_replace("/\//", "\/", $word);
- $line = preg_replace("/(=(\"|')[^\"']*[$sep'])$pregword([$sep][^\"']*(\"|'))/i", "$1:::::$word,:::::$3", $line);
- $line = preg_replace("/([$sep']|^)$pregword($|[$sep])/i", "$1<a class=\"wiki\" href=\"$url\" $hotw_nw>$word</a>$2", $line);
- $line = preg_replace("/:::::$pregword,:::::/i", "$word", $line);
+ $escapedWord = preg_quote($word, '/');
+ $line = preg_replace("/(=(\"|')[^\"']*[$sep'])$escapedWord([$sep][^\"']*(\"|'))/i", "$1:::::$word,:::::$3", $line);
+ $line = preg_replace("/([$sep']|^)$escapedWord($|[$sep])/i", "$1<a class=\"wiki\" href=\"$url\" $hotw_nw>$word</a>$2", $line);
+ $line = preg_replace("/:::::$escapedWord,:::::/i", "$word", $line);
  }
  }
  return $line;

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
Tikiwiki-cvs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs

------------------------------------------------------------------------------
Announcing the Oxford Dictionaries API! The API offers world-renowned
dictionary content that is easy and intuitive to access. Sign up for an
account today to start using our lexical data to power your apps and
projects. Get started today and enter our developer competition.
http://sdm.link/oxford
_______________________________________________
TikiWiki-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tiki-devel] PCRE metacharacters in hotwords (RE: [Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[61559] trunk/lib/parser/parserlib.php)

Cloutier, Philippe (RESSOURCE EXTERNE)
Hi,
I backported this to 16.x, 15.x and 12.x in r62436, r62437 and r62438.

> -----Message d'origine-----
> De : Cloutier, Philippe (RESSOURCE EXTERNE) [mailto:[hidden email]]
> Envoyé : 8 mars 2017 15:13
> À : 'Tiki developers' <[hidden email]>
> Objet : [Tiki-devel] PCRE metacharacters in hotwords (RE: [Tikiwiki-cvs/svn] SF.net SVN:
> tikiwiki:[61559] trunk/lib/parser/parserlib.php)
>
> Hi,
> r61559 fixes 2 issues which could happen when a hotword contained PCRE metacharacters:
> 1. If the resulting pattern was invalid, the result of parsing would be empty.
> 2. Hotwords would match text different from the hotword itself (for example, "I.O." would match
> "IGOR")
>
> This fix causes each hotword to match only the word literally. I intend to backport to Tiki 12. The
> previous behavior of interpreting the hotword as a pattern was not documented. If someone
> intentionally used such patterns, please say so.
>
> -----Message d'origine-----
> De : [hidden email] [mailto:[hidden email]]
> Envoyé : 7 mars 2017 16:33
> À : [hidden email]
> Objet : [Tikiwiki-cvs/svn] SF.net SVN: tikiwiki:[61559] trunk/lib/parser/parserlib.php
>
> Revision: 61559
>           http://sourceforge.net/p/tikiwiki/code/61559
> Author:   chealer
> Date:     2017-03-07 21:33:16 +0000 (Tue, 07 Mar 2017)
> Log Message:
> -----------
> [FIX] replace_hotwords(): empty lines returned when some hotwords containing PCRE
> metacharacters are present
> Escape all PCRE metacharacters rather than just slashes.
> Was already present in 2006
>
> Modified Paths:
> --------------
>     trunk/lib/parser/parserlib.php
>
> Modified: trunk/lib/parser/parserlib.php
> ===================================================================
> --- trunk/lib/parser/parserlib.php 2017-03-07 19:07:16 UTC (rev 61558)
> +++ trunk/lib/parser/parserlib.php 2017-03-07 21:33:16 UTC (rev 61559)
> @@ -1357,10 +1357,10 @@
>   $sep = empty($sep)? " \n\t\r\,\;\(\)\.\:\[\]\{\}\!\?\"":"$sep";
>   foreach ($words as $word => $url) {
>   // \b is a word boundary, \s is a space char
> - $pregword = preg_replace("/\//", "\/", $word);
> - $line =
> preg_replace("/(=(\"|')[^\"']*[$sep'])$pregword([$sep][^\"']*(\"|'))/i", "$1:::::$word,:::::$3", $line);
> - $line = preg_replace("/([$sep']|^)$pregword($|[$sep])/i", "$1<a
> class=\"wiki\" href=\"$url\" $hotw_nw>$word</a>$2", $line);
> - $line = preg_replace("/:::::$pregword,:::::/i", "$word", $line);
> + $escapedWord = preg_quote($word, '/');
> + $line =
> preg_replace("/(=(\"|')[^\"']*[$sep'])$escapedWord([$sep][^\"']*(\"|'))/i", "$1:::::$word,:::::$3",
> $line);
> + $line = preg_replace("/([$sep']|^)$escapedWord($|[$sep])/i", "$1<a
> class=\"wiki\" href=\"$url\" $hotw_nw>$word</a>$2", $line);
> + $line = preg_replace("/:::::$escapedWord,:::::/i", "$word", $line);
>   }
>   }
>   return $line;
>
> This was sent by the SourceForge.net collaborative development platform, the world's largest Open
> Source development site.
>
>
> ------------------------------------------------------------------------------
> Announcing the Oxford Dictionaries API! The API offers world-renowned
> dictionary content that is easy and intuitive to access. Sign up for an
> account today to start using our lexical data to power your apps and
> projects. Get started today and enter our developer competition.
> http://sdm.link/oxford
> _______________________________________________
> Tikiwiki-cvs mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
>
> ------------------------------------------------------------------------------
> Announcing the Oxford Dictionaries API! The API offers world-renowned
> dictionary content that is easy and intuitive to access. Sign up for an
> account today to start using our lexical data to power your apps and
> projects. Get started today and enter our developer competition.
> http://sdm.link/oxford
> _______________________________________________
> TikiWiki-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
TikiWiki-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-devel
Loading...