Skip to content

Commit

Permalink
Merge pull request #678 from kethinov/0.6.9
Browse files Browse the repository at this point in the history
0.6.9
  • Loading branch information
kethinov authored Jul 27, 2024
2 parents 15741e8 + da0f139 commit 1559ec2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

- Put your changes here...

## 0.6.9

- Fixed issue with rendering variables with empty strings piped through variables with flags.
- Updated various dependencies.

## 0.6.8

- Fixed issue with rendering special characters correctly when piped through a teddy noparse flagged variable.
Expand Down
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "https://github.com/rooseveltframework/teddy/graphs/contributors"
}
],
"version": "0.6.8",
"version": "0.6.9",
"files": [
"dist"
],
Expand All @@ -35,7 +35,7 @@
"c8": "10.1.2",
"codecov": "3.8.3",
"cross-env": "7.0.3",
"eslint": "9.7.0",
"eslint": "9.8.0",
"eslint-plugin-html": "8.1.1",
"eslint-plugin-mocha": "10.4.3",
"mocha": "10.7.0",
Expand Down
7 changes: 4 additions & 3 deletions teddy.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ function parseVars (templateString, model) {
const originalMatch = match
match = match.substring(0, match.length - (lastFourChars.split('|').length - 1 > 1 ? 4 : 2)) // remove last 2-4 char
const parsed = getOrSetObjectByDotNotation(model, match)
if (parsed) {
if (parsed || parsed === '') {
const id = model._noTeddyBlocks.push(parsed) - 1
try {
try {
Expand All @@ -669,8 +669,9 @@ function parseVars (templateString, model) {
} else if (lastFourChars.includes('|s')) {
// no escape flag is set
const originalMatch = match
match = match.substring(0, match.length - 2) // remove last 2 char
const parsed = getOrSetObjectByDotNotation(model, match) || `{${originalMatch}}`
match = match.substring(0, match.length - (lastFourChars.split('|').length - 1 > 1 ? 4 : 2)) // remove last 2-4 char
let parsed = getOrSetObjectByDotNotation(model, match)
if (!parsed && parsed !== '') parsed = `{${originalMatch}}`
try {
templateString = templateString.replace(new RegExp(`{${originalMatch}}`.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d'), 'i'), () => parsed)
} catch (e) {
Expand Down
20 changes: 20 additions & 0 deletions test/templates/misc/emptyStringVariableFlags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{!
should render empty strings as is for |p or |s variables that are empty strings
!}

<p>{emptyString|p}</p>

<p>{definedParent.emptyMember|p}</p>

<p>{emptyString|s}</p>

<p>{definedParent.emptyMember|s}</p>

<p>{emptyString|p|s}</p>

<p>{definedParent.emptyMember|p|s}</p>

<p>{emptyString|s|p}</p>

<p>{definedParent.emptyMember|s|p}</p>

6 changes: 6 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,12 @@ export default [
template: 'misc/specialChars',
test: (teddy, template, model) => teddy.render(template, model),
expected: '<p>special .$&@. chars</p>'
},
{
message: 'should render empty strings as is for |p or |s variables that are empty strings (misc/emptyStringVariableFlags.html)',
template: 'misc/emptyStringVariableFlags',
test: (teddy, template, model) => teddy.render(template, model),
expected: '<p></p><p></p><p></p><p></p><p></p><p></p><p></p><p></p>'
}
// ,{
// message: '',
Expand Down

0 comments on commit 1559ec2

Please sign in to comment.