Plugin Directory

Changeset 3290429


Ignore:
Timestamp:
05/09/2025 11:27:55 AM (11 months ago)
Author:
jumptech
Message:

Update to version 1.1.7--beta-2 from GitHub

Location:
avacy
Files:
2 deleted
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • avacy/tags/1.1.7--beta-2/src/Integrations/HtmlForms.php

    r3239361 r3290429  
    107107    private static function parseFields($fields) {
    108108        $parsedFields = [];
    109 
     109   
     110        if (empty($fields) || !is_string($fields)) {
     111            return $parsedFields;
     112        }
     113   
     114        // Gestione errori libxml
     115        libxml_use_internal_errors(true);
     116   
     117        // Escape degli & non validi
     118        $fields = preg_replace('/&(?![a-zA-Z0-9#]+;)/', '&', $fields);
     119   
    110120        $dom = new DOMDocument();
    111         $dom->loadHTML($fields);
     121        try {
     122            $dom->loadHTML($fields, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
     123        } catch (\Exception $e) {
     124            // Log or handle the error if needed
     125            libxml_clear_errors();
     126            return $parsedFields;
     127        }
     128   
    112129        $inputs = $dom->getElementsByTagName('input');
    113 
     130   
    114131        foreach($inputs as $input) {
    115132            $attrs = $input->attributes;
    116 
     133   
    117134            foreach($attrs as $attrName => $attrValue) {
    118135                if($attrName === 'name') {
     
    123140                    ];
    124141                }
    125 
    126142            }
    127143        }
    128 
     144   
     145        libxml_clear_errors();
     146   
    129147        return $parsedFields;
    130148    }
  • avacy/tags/1.1.7--beta-2/src/PreemptiveBlock.php

    r3286076 r3290429  
    5555
    5656    public static function output_callback( $buffer ) {
    57         // Modify $buffer (HTML content) here
    58 
     57        // Suppress warnings from malformed HTML
     58        libxml_use_internal_errors(true);
     59   
     60        // Escape ampersands not part of entities
     61        $buffer = preg_replace('/&(?![a-zA-Z0-9#]+;)/', '&', $buffer);
     62   
    5963        $dom = new DOMDocument();
    6064        $dom->loadHTML($buffer, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    61 
    62         if( !empty($buffer) ) {
    6365   
     66        if (!empty($buffer)) {
    6467            $scripts = $dom->getElementsByTagName('script');
    6568            foreach($scripts as $script) {
    66                 // if src is in the list of scripts to block
    6769                $src = $script->getAttribute('src');
    68 
    69                 if ( ( $src !== '' && ($emt = self::src_contains($src, self::$blackList)) ) ||
    70                      ( $emt = self::inner_html_contains($script, self::$blackList) ) ) {
    71 
    72                     // change script type to text/plain
     70   
     71                if (($src !== '' && ($emt = self::src_contains($src, self::$blackList))) ||
     72                    ($emt = self::inner_html_contains($script, self::$blackList))) {
     73   
    7374                    $script->setAttribute('type', 'as-oil');
    7475                    $script->setAttribute('data-src', $src);
    75    
    76                     // add avacy attributes
    7776                    $script->setAttribute('data-managed', 'as-oil');
    7877                    $script->setAttribute('data-type', 'text/javascript');
    79    
    80                     // add vendor
    8178                    $script->setAttribute($emt['attribute'], $emt['id']);
    82    
    83                     // add purposes
    8479                    $script->setAttribute('data-purposes', implode(',', $emt['purposes']));
    8580                }
    8681            }
    87 
    8882        }
    89 
    90         $buffer = $dom->saveHTML();
    91         return $buffer;
     83   
     84        // Clear libxml errors
     85        libxml_clear_errors();
     86   
     87        return $dom->saveHTML();
    9288    }
    9389
  • avacy/trunk/src/Integrations/HtmlForms.php

    r3239361 r3290429  
    107107    private static function parseFields($fields) {
    108108        $parsedFields = [];
    109 
     109   
     110        if (empty($fields) || !is_string($fields)) {
     111            return $parsedFields;
     112        }
     113   
     114        // Gestione errori libxml
     115        libxml_use_internal_errors(true);
     116   
     117        // Escape degli & non validi
     118        $fields = preg_replace('/&(?![a-zA-Z0-9#]+;)/', '&', $fields);
     119   
    110120        $dom = new DOMDocument();
    111         $dom->loadHTML($fields);
     121        try {
     122            $dom->loadHTML($fields, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
     123        } catch (\Exception $e) {
     124            // Log or handle the error if needed
     125            libxml_clear_errors();
     126            return $parsedFields;
     127        }
     128   
    112129        $inputs = $dom->getElementsByTagName('input');
    113 
     130   
    114131        foreach($inputs as $input) {
    115132            $attrs = $input->attributes;
    116 
     133   
    117134            foreach($attrs as $attrName => $attrValue) {
    118135                if($attrName === 'name') {
     
    123140                    ];
    124141                }
    125 
    126142            }
    127143        }
    128 
     144   
     145        libxml_clear_errors();
     146   
    129147        return $parsedFields;
    130148    }
  • avacy/trunk/src/PreemptiveBlock.php

    r3286076 r3290429  
    5555
    5656    public static function output_callback( $buffer ) {
    57         // Modify $buffer (HTML content) here
    58 
     57        // Suppress warnings from malformed HTML
     58        libxml_use_internal_errors(true);
     59   
     60        // Escape ampersands not part of entities
     61        $buffer = preg_replace('/&(?![a-zA-Z0-9#]+;)/', '&', $buffer);
     62   
    5963        $dom = new DOMDocument();
    6064        $dom->loadHTML($buffer, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    61 
    62         if( !empty($buffer) ) {
    6365   
     66        if (!empty($buffer)) {
    6467            $scripts = $dom->getElementsByTagName('script');
    6568            foreach($scripts as $script) {
    66                 // if src is in the list of scripts to block
    6769                $src = $script->getAttribute('src');
    68 
    69                 if ( ( $src !== '' && ($emt = self::src_contains($src, self::$blackList)) ) ||
    70                      ( $emt = self::inner_html_contains($script, self::$blackList) ) ) {
    71 
    72                     // change script type to text/plain
     70   
     71                if (($src !== '' && ($emt = self::src_contains($src, self::$blackList))) ||
     72                    ($emt = self::inner_html_contains($script, self::$blackList))) {
     73   
    7374                    $script->setAttribute('type', 'as-oil');
    7475                    $script->setAttribute('data-src', $src);
    75    
    76                     // add avacy attributes
    7776                    $script->setAttribute('data-managed', 'as-oil');
    7877                    $script->setAttribute('data-type', 'text/javascript');
    79    
    80                     // add vendor
    8178                    $script->setAttribute($emt['attribute'], $emt['id']);
    82    
    83                     // add purposes
    8479                    $script->setAttribute('data-purposes', implode(',', $emt['purposes']));
    8580                }
    8681            }
    87 
    8882        }
    89 
    90         $buffer = $dom->saveHTML();
    91         return $buffer;
     83   
     84        // Clear libxml errors
     85        libxml_clear_errors();
     86   
     87        return $dom->saveHTML();
    9288    }
    9389
Note: See TracChangeset for help on using the changeset viewer.