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


##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/WordExtractor.java:
##########
@@ -170,14 +173,27 @@ public static TagAndStyle 
buildParagraphTagAndStyle(String styleName, boolean is
             // Turn it into a H1 - H6 (H7+ isn't valid!)
             tag = "h" + Math.min(num, 6);
         } else {
-            styleClass = styleName.replace(' ', '_');
-            styleClass =
-                    styleClass.substring(0, 1).toLowerCase(Locale.ROOT) + 
styleClass.substring(1);
+            styleClass = toStyleClass(styleName);
         }
 
         return new TagAndStyle(tag, styleClass);
     }
 
+    /**
+     * @return the XHTML class for a style name, e.g. "List Bullet" -> 
"list_Bullet",
+     * or null for an empty name. Anything but letters, digits, '_' and '-' 
becomes '_',
+     * so a style name can never yield more than one class token.
+     */
+    public static String toStyleClass(String styleName) {
+        if (styleName == null || styleName.isEmpty()) {
+            return null;
+        }
+        String styleClass = styleName.length() > MAX_STYLE_CLASS_LENGTH
+                ? styleName.substring(0, MAX_STYLE_CLASS_LENGTH) : styleName;
+        styleClass = NON_STYLE_CLASS_CHARS.matcher(styleClass).replaceAll("_");
+        return styleClass.substring(0, 1).toLowerCase(Locale.ROOT) + 
styleClass.substring(1);

Review Comment:
   Sanitization happens before lowercasing, but Unicode lowercasing can expand 
a permitted letter (for example, `İ` becomes `i` plus a combining mark). That 
reintroduces a disallowed character and can make a 128-character result 129 
characters long, contradicting both this method's contract and the release 
note. Lowercase the first code point before sanitizing and applying a 
code-point-safe length cap.



##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-microsoft-module/src/main/java/org/apache/tika/parser/microsoft/ooxml/xwpf/XWPFStylesShim.java:
##########
@@ -72,7 +75,45 @@ public String getStyleName(String styleId) {
         if (styleId == null) {
             return null;
         }
-        return styles.get(styleId);
+        StyleInfo info = styles.get(styleId);
+        return info == null ? null : info.name;
+    }
+
+    /**
+     * @return whether the style, or the nearest style it is based on that says
+     * either way, sets bold; false if none does
+     */
+    public boolean isBold(String styleId) {
+        StyleInfo info = styles.get(styleId);
+        for (int i = 0; info != null && i < MAX_BASED_ON_DEPTH; i++) {
+            if (info.bold != null) {
+                return info.bold;

Review Comment:
   OOXML run-style bold is a toggle property, not a nearest-value override. A 
derived style containing `<w:b/>` must invert inherited bold, while `<w:b 
w:val="false"/>` leaves the inherited state unchanged; this method returns the 
opposite result in both cases. Resolve the chain by accumulating true toggles 
(and ignoring false values), and update the fixture expectations accordingly.
   
   This issue also appears on line 104 of the same file.



##########
CHANGES.txt:
##########
@@ -1,5 +1,13 @@
 Release 4.2.0 - unreleased
 
+   * The docx parser now applies bold and italics set by a run's character 
style
+     (e.g. Word's built-in Strong and Emphasis), following basedOn chains; 
previously
+     only direct formatting was emitted. The new OfficeParserConfig option
+     includeCharacterStyleClasses wraps such runs in <span class="..."> named 
after
+     the style. Style-derived classes (paragraph and character) now replace 
every
+     character other than letters, digits, '_' and '-' with '_' and are capped 
at 128
+     characters, so a style name can no longer yield extra class tokens 
(TIKA-4966).

Review Comment:
   This entry references TIKA-4966, but the pull request and feature are 
tracked as TIKA-4996. Using the wrong issue ID prevents the release note from 
linking this change to its actual ticket.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to