[ 
https://issues.apache.org/jira/browse/TIKA-4745?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18086429#comment-18086429
 ] 

ASF GitHub Bot commented on TIKA-4745:
--------------------------------------

Copilot commented on code in PR #2872:
URL: https://github.com/apache/tika/pull/2872#discussion_r3363963514


##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-html-module/src/main/java/org/apache/tika/parser/html/JSoupParser.java:
##########
@@ -165,6 +166,9 @@ public void parse(TikaInputStream tis, ContentHandler 
handler, Metadata metadata
                 : encResults.get(0).getCharset();
         Charset decodeAs = encResults.isEmpty() ? DEFAULT_CHARSET
                 : encResults.get(0).getDecodeAs();
+        if (!decodeAs.equals(charset)) {
+            metadata.set(TikaCoreProperties.DECODED_CHARSET, decodeAs.name());
+        }

Review Comment:
   `DECODED_CHARSET` is only set when `decodeAs` differs from the detected 
`charset`, but it is never cleared when they are equal. If the same `Metadata` 
instance is reused across parses, a previously-set `decodedCharset` value can 
leak into a later parse that did *not* use a superset override, misleading 
callers about which charset was actually used. Clear the field before 
conditionally setting it for this parse.





> Small improvements to lang detection, charset detection and junk detection
> --------------------------------------------------------------------------
>
>                 Key: TIKA-4745
>                 URL: https://issues.apache.org/jira/browse/TIKA-4745
>             Project: Tika
>          Issue Type: Task
>            Reporter: Tim Allison
>            Priority: Minor
>
> I ran a regression test in prep for the 4.0.0-beta-1 release. There are a 
> number of smallish things that we can clean up in the components listed in 
> the title.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to