@@ -807,7 +807,20 @@ class Workbook {
807
807
// is the entirety of the string) and `type` (one of `table` or `cell`)
808
808
extractPlaceholders ( string ) {
809
809
// Yes, that's right. It's a bunch of brackets and question marks and stuff.
810
- var re = / \$ { (?: ( .+ ?) : ) ? ( .+ ?) (?: \. ( .+ ?) ) ? (?: : ( .+ ?) ) ? ?} / g;
810
+ // IMPORTANT: Instead of matching 'any character' on every capture (by using a dot),
811
+ // it captures 'any except colon and brackets' by using [^{}:] to avoid
812
+ // a bug where the expression will consume the text in a 'greedy' way,
813
+ // capturing colon characters from outside the placeholder (after a closing
814
+ // bracket).
815
+ // Since that characters are already managed in the RegExp as separators
816
+ // of capture groups, it will still match the whole expression,
817
+ // but in a safe way (by including brackets and not only the colon from
818
+ // the exclusion, it avoids other kinds of mistakes and wrong placeholder
819
+ // syntax, but if compatibility is a concern they could be removed and
820
+ // left like [^:] ).
821
+ // (The non-greedy modifier should have done that, but it's more difficult
822
+ // to get it right than expected)
823
+ var re = / \$ { (?: ( [ ^ { } : ] + ?) : ) ? ( [ ^ { } : ] + ?) (?: \. ( [ ^ { } : ] + ?) ) ? (?: : ( [ ^ { } : ] + ?) ) ? ?} / g;
811
824
812
825
var match = null , matches = [ ] ;
813
826
while ( ( match = re . exec ( string ) ) !== null ) {
@@ -1061,14 +1074,14 @@ class Workbook {
1061
1074
let mergeCell = self . sheet . root . findall ( "mergeCells/mergeCell" )
1062
1075
. find ( c => self . splitRange ( c . attrib . ref ) . start === cell . attrib . r )
1063
1076
let isMergeCell = mergeCell != null
1064
-
1077
+
1065
1078
if ( isMergeCell ) {
1066
1079
let originalMergeRange = self . splitRange ( mergeCell . attrib . ref ) ,
1067
1080
originalMergeStart = self . splitRef ( originalMergeRange . start ) ,
1068
1081
originalMergeEnd = self . splitRef ( originalMergeRange . end ) ;
1069
-
1082
+
1070
1083
for ( let colnum = self . charToNum ( originalMergeStart . col ) + 1 ; colnum <= self . charToNum ( originalMergeEnd . col ) ; colnum ++ ) {
1071
- const originalRow = self . sheet . root . find ( 'sheetData' ) . _children . find ( f => f . attrib . r == originalMergeStart . row )
1084
+ const originalRow = self . sheet . root . find ( 'sheetData' ) . _children . find ( f => f . attrib . r == originalMergeStart . row )
1072
1085
let col = self . numToChar ( colnum )
1073
1086
let originalCell = originalRow . _children . find ( f => f . attrib . r . startsWith ( col ) )
1074
1087
@@ -1698,7 +1711,7 @@ class Workbook {
1698
1711
getWidthCell ( numCol , sheet ) {
1699
1712
var defaultWidth = sheet . root . find ( "sheetFormatPr" ) . attrib [ "defaultColWidth" ] ;
1700
1713
if ( ! defaultWidth ) {
1701
- // TODO : Check why defaultColWidth is not set ?
1714
+ // TODO : Check why defaultColWidth is not set ?
1702
1715
defaultWidth = 11.42578125 ;
1703
1716
}
1704
1717
var finalWidth = defaultWidth ;
@@ -1751,7 +1764,7 @@ class Workbook {
1751
1764
}
1752
1765
columnWidthToEMUs ( width ) {
1753
1766
// TODO : This is not the true. Change with true calcul
1754
- // can find help here :
1767
+ // can find help here :
1755
1768
// https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-column-widths
1756
1769
// https://stackoverflow.com/questions/58021996/how-to-set-the-fixed-column-width-values-in-inches-apache-poi
1757
1770
// https://poi.apache.org/apidocs/dev/org/apache/poi/ss/usermodel/Sheet.html#setColumnWidth-int-int-
@@ -1766,9 +1779,9 @@ class Workbook {
1766
1779
}
1767
1780
/**
1768
1781
* Find max file id.
1769
- * @param {RegExp } fileNameRegex
1770
- * @param {RegExp } idRegex
1771
- * @returns {number }
1782
+ * @param {RegExp } fileNameRegex
1783
+ * @param {RegExp } idRegex
1784
+ * @returns {number }
1772
1785
*/
1773
1786
findMaxFileId ( fileNameRegex , idRegex ) {
1774
1787
var self = this ;
0 commit comments