Fossil SCM
Fix the TH_ListAppend() function in TH1 so that it correctly escapes strings that have a '}' character that has no matching '{' to its left. Fix for ticket [4d73b4a2258a78e2].
Commit
4ec65ebba9177429ce8caafd49d2f2c1ee52679bca14cd703baaaa8253558590
Parent
f0e625b1aa6a81a…
1 file changed
+13
-4
M
src/th.c
+13
-4
| --- src/th.c | ||
| +++ src/th.c | ||
| @@ -1750,12 +1750,12 @@ | ||
| 1750 | 1750 | int nElem /* Length of nElem */ |
| 1751 | 1751 | ){ |
| 1752 | 1752 | Buffer output; |
| 1753 | 1753 | int i; |
| 1754 | 1754 | |
| 1755 | - int hasSpecialChar = 0; | |
| 1756 | - int hasEscapeChar = 0; | |
| 1755 | + int hasSpecialChar = 0; /* Whitespace or {}[]'" */ | |
| 1756 | + int hasEscapeChar = 0; /* '}' without matching '{' to the left or a '\\' */ | |
| 1757 | 1757 | int nBrace = 0; |
| 1758 | 1758 | |
| 1759 | 1759 | output.zBuf = *pzList; |
| 1760 | 1760 | output.nBuf = *pnList; |
| 1761 | 1761 | output.nBufAlloc = output.nBuf; |
| @@ -1768,13 +1768,22 @@ | ||
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | for(i=0; i<nElem; i++){ |
| 1771 | 1771 | char c = zElem[i]; |
| 1772 | 1772 | if( th_isspecial(c) ) hasSpecialChar = 1; |
| 1773 | - if( c=='\\' ) hasEscapeChar = 1; | |
| 1773 | + if( c=='\\' ){ hasEscapeChar = 1; break; } | |
| 1774 | 1774 | if( c=='{' ) nBrace++; |
| 1775 | - if( c=='}' ) nBrace--; | |
| 1775 | + if( c=='}' ){ | |
| 1776 | + if( nBrace==0 ){ | |
| 1777 | + /* A closing brace that does not have a matching open brace to | |
| 1778 | + ** its left needs to be excaped. See ticket 4d73b4a2258a78e2 */ | |
| 1779 | + hasEscapeChar = 1; | |
| 1780 | + break; | |
| 1781 | + }else{ | |
| 1782 | + nBrace--; | |
| 1783 | + } | |
| 1784 | + } | |
| 1776 | 1785 | } |
| 1777 | 1786 | |
| 1778 | 1787 | if( nElem==0 || (!hasEscapeChar && hasSpecialChar && nBrace==0) ){ |
| 1779 | 1788 | thBufferAddChar(interp, &output, '{'); |
| 1780 | 1789 | thBufferWrite(interp, &output, zElem, nElem); |
| 1781 | 1790 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1750,12 +1750,12 @@ | |
| 1750 | int nElem /* Length of nElem */ |
| 1751 | ){ |
| 1752 | Buffer output; |
| 1753 | int i; |
| 1754 | |
| 1755 | int hasSpecialChar = 0; |
| 1756 | int hasEscapeChar = 0; |
| 1757 | int nBrace = 0; |
| 1758 | |
| 1759 | output.zBuf = *pzList; |
| 1760 | output.nBuf = *pnList; |
| 1761 | output.nBufAlloc = output.nBuf; |
| @@ -1768,13 +1768,22 @@ | |
| 1768 | } |
| 1769 | |
| 1770 | for(i=0; i<nElem; i++){ |
| 1771 | char c = zElem[i]; |
| 1772 | if( th_isspecial(c) ) hasSpecialChar = 1; |
| 1773 | if( c=='\\' ) hasEscapeChar = 1; |
| 1774 | if( c=='{' ) nBrace++; |
| 1775 | if( c=='}' ) nBrace--; |
| 1776 | } |
| 1777 | |
| 1778 | if( nElem==0 || (!hasEscapeChar && hasSpecialChar && nBrace==0) ){ |
| 1779 | thBufferAddChar(interp, &output, '{'); |
| 1780 | thBufferWrite(interp, &output, zElem, nElem); |
| 1781 |
| --- src/th.c | |
| +++ src/th.c | |
| @@ -1750,12 +1750,12 @@ | |
| 1750 | int nElem /* Length of nElem */ |
| 1751 | ){ |
| 1752 | Buffer output; |
| 1753 | int i; |
| 1754 | |
| 1755 | int hasSpecialChar = 0; /* Whitespace or {}[]'" */ |
| 1756 | int hasEscapeChar = 0; /* '}' without matching '{' to the left or a '\\' */ |
| 1757 | int nBrace = 0; |
| 1758 | |
| 1759 | output.zBuf = *pzList; |
| 1760 | output.nBuf = *pnList; |
| 1761 | output.nBufAlloc = output.nBuf; |
| @@ -1768,13 +1768,22 @@ | |
| 1768 | } |
| 1769 | |
| 1770 | for(i=0; i<nElem; i++){ |
| 1771 | char c = zElem[i]; |
| 1772 | if( th_isspecial(c) ) hasSpecialChar = 1; |
| 1773 | if( c=='\\' ){ hasEscapeChar = 1; break; } |
| 1774 | if( c=='{' ) nBrace++; |
| 1775 | if( c=='}' ){ |
| 1776 | if( nBrace==0 ){ |
| 1777 | /* A closing brace that does not have a matching open brace to |
| 1778 | ** its left needs to be excaped. See ticket 4d73b4a2258a78e2 */ |
| 1779 | hasEscapeChar = 1; |
| 1780 | break; |
| 1781 | }else{ |
| 1782 | nBrace--; |
| 1783 | } |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | if( nElem==0 || (!hasEscapeChar && hasSpecialChar && nBrace==0) ){ |
| 1788 | thBufferAddChar(interp, &output, '{'); |
| 1789 | thBufferWrite(interp, &output, zElem, nElem); |
| 1790 |