ljunkie / plexWatch

Notify and Log watched content on a Plex Media Server
430 stars 59 forks source link

Fixed: Unescaped left brace in regex is deprecated... #124

Open JesseHawkins-zz opened 8 years ago

JesseHawkins-zz commented 8 years ago

I'm probably posting this in the wrong area, so please excuse my GitHub-noobyness.

When running plexWatch.pl, I was greeted with a few occurrences of, "Unescaped left brace in regex is deprecated..." along with line numbers. A quick Google indicates that curly braces need to be escaped to fix this error message, and that eventually this error message will become a syntax error. Seemed like a good enough justification to find a fix.

My modified script runs without issues, as far as I can tell, after I made these changes:

    $format =~ s/{{($regex)}}/$info->{$1}/g; ## regex replace variables
    $format =~ s/\[\]//g;                 ## trim any empty variable encapsulated in []
    $format =~ s/\s+/ /g;                 ## remove double spaces
    $format =~ s/\\n/\n/g;                ## allow \n to be an actual new line
    $format =~ s/{{newline}}/\n/g;        ## allow \n to be an actual new line

    ## special for now.. might make this more useful -- just thrown together since email can include a ton of info

    if ($format =~ /{{all_details}}/i) {
        $format =~ s/\s*{{all_details}}\s*//i;

Changed to:

    $format =~ s/\{\{($regex)\}\}/$info->{$1}/g; ## regex replace variables
    $format =~ s/\[\]//g;                 ## trim any empty variable encapsulated in []
    $format =~ s/\s+/ /g;                 ## remove double spaces
    $format =~ s/\\n/\n/g;                ## allow \n to be an actual new line
    $format =~ s/\{\{newline\}\}/\n/g;        ## allow \n to be an actual new line

    ## special for now.. might make this more useful -- just thrown together since email can include a ton of info

    if ($format =~ /\{\{all_details\}\}/i) {
        $format =~ s/\s*\{\{all_details\}\}\s*//i;

Hope that this is helpful to someone. :)

rubicon commented 8 years ago

Thanks for pointing this out. I escaped the { and } on lines 760, 764, 765 thanks to this direction. Only lines I needed to change to fix the errors I was getting, but wouldn't have figured it out without this post. Thanks a lot!

C-Duv commented 7 years ago

Thanks for the info, I was also about to fix it like this and found the confirmation here.

Here is a patch for fast command-line patching:

--- plexWatch.pl        2017-08-07 01:51:45.641446183 +0200
+++ plexWatch.pl        2017-08-07 01:52:33.442447850 +0200
@@ -757,12 +757,12 @@
     $format =~ s/\[\]//g;                 ## trim any empty variable encapsulated in []
     $format =~ s/\s+/ /g;                 ## remove double spaces
     $format =~ s/\\n/\n/g;                ## allow \n to be an actual new line
-    $format =~ s/{{newline}}/\n/g;        ## allow \n to be an actual new line
+    $format =~ s/\{\{newline\}\}/\n/g;    ## allow \n to be an actual new line

     ## special for now.. might make this more useful -- just thrown together since email can include a ton of info

-    if ($format =~ /{{all_details}}/i) {
-        $format =~ s/\s*{{all_details}}\s*//i;
+    if ($format =~ /\{\{all_details\}\}/i) {
+        $format =~ s/\s*\{\{all_details\}\}\s*//i;
         $format .= sprintf("\n\n%10s %s\n","","-----All Details-----");
         my $f_extra;
         foreach my $key (keys %{$info} ) {

Apply patch with:

patch plexWatch.pl patch_file