diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-09-01 09:26:27 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-09-01 12:13:23 +0200 |
commit | 8e5044d7f5af5f3454e65860809f4a23692a0b00 (patch) | |
tree | dc3bb2c595f09ac55db645621e8ad6b7851270cc /parser | |
parent | 5046a6c7ca1cec914c5f1347799bb30a9d45854a (diff) | |
download | hugo-8e5044d7f5af5f3454e65860809f4a23692a0b00.tar.gz hugo-8e5044d7f5af5f3454e65860809f4a23692a0b00.zip |
Fix shortcode parser regression with quoted param values
This issue was introduced in `v0.102.0`.
In 223bf2800488ad5d38854bbb595d789bc35ebe32 we removed the byte source from the parsed page result, which
meant we had to preserve exact positioning for all elements. This introduced some new `TypeIgnore` tokens
which we, wrongly, assumed didn't matter where we put in the result slice (they should be ignored anyway).
But it seems that this broke the logic where we determine if it's positional or named params in the case
where the paramater value contains escaped quoutes.
This commit makes sure that these ignore tokens (the back slashes) are never sent back to the client, which is how it was before `v0.102.0`.
This commit also fixes some lost error information in that same commit.
Fixes #10236
Diffstat (limited to 'parser')
-rw-r--r-- | parser/pageparser/pagelexer.go | 7 | ||||
-rw-r--r-- | parser/pageparser/pageparser_shortcode_test.go | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/parser/pageparser/pagelexer.go b/parser/pageparser/pagelexer.go index a7e6b6cd4..5f5d147e6 100644 --- a/parser/pageparser/pagelexer.go +++ b/parser/pageparser/pagelexer.go @@ -194,7 +194,12 @@ func (l *pageLexer) ignoreEscapesAndEmit(t ItemType, isString bool) { if i > k { segments = append(segments, lowHigh{k, i}) } - l.append(Item{Type: TypeIgnore, low: i, high: i + w}) + // See issue #10236. + // We don't send the backslash back to the client, + // which makes the end parsing simpler. + // This means that we cannot render the AST back to be + // exactly the same as the input, + // but that was also the situation before we introduced the issue in #10236. k = i + w } i += w diff --git a/parser/pageparser/pageparser_shortcode_test.go b/parser/pageparser/pageparser_shortcode_test.go index a95d55ef3..26d836e32 100644 --- a/parser/pageparser/pageparser_shortcode_test.go +++ b/parser/pageparser/pageparser_shortcode_test.go @@ -40,7 +40,6 @@ var ( tstParamFloat = nti(tScParam, "3.14") tstVal = nti(tScParamVal, "Hello World") tstText = nti(tText, "Hello World") - tstIgnoreEscape = nti(TypeIgnore, "\\") ) var shortCodeLexerTests = []lexerTest{ @@ -179,14 +178,14 @@ var shortCodeLexerTests = []lexerTest{ "escaped quotes inside nonescaped quotes", `{{< sc1 param1="Hello \"escaped\" World" >}}`, []typeText{ - tstLeftNoMD, tstSC1, tstParam1, tstIgnoreEscape, tstIgnoreEscape, nti(tScParamVal, `Hello "escaped" World`), tstRightNoMD, tstEOF, + tstLeftNoMD, tstSC1, tstParam1, nti(tScParamVal, `Hello "escaped" World`), tstRightNoMD, tstEOF, }, }, { "escaped quotes inside nonescaped quotes in positional param", `{{< sc1 "Hello \"escaped\" World" >}}`, []typeText{ - tstLeftNoMD, tstSC1, tstIgnoreEscape, tstIgnoreEscape, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF, + tstLeftNoMD, tstSC1, nti(tScParam, `Hello "escaped" World`), tstRightNoMD, tstEOF, }, }, {"escaped raw string, named param", `{{< sc1 param1=` + `\` + "`" + "Hello World" + `\` + "`" + ` >}}`, []typeText{ |