Skip to content

Commit

Permalink
Bugfix - Fixing error when using single quotation mark on html
Browse files Browse the repository at this point in the history
  • Loading branch information
Javiani committed Aug 12, 2023
1 parent d5cf6d2 commit c4ef784
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jails-js",
"version": "5.1.0",
"version": "5.1.1",
"description": "Jails - Elegant and Minimalistic Javascript Application Library",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions src/template-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const templateConfig = (newconfig) => {
export default function Template(element, $scopes) {

element.initialState = getInitialState( element )
const html = Transpile(element.outerHTML, config, $scopes)
textarea.innerHTML = html
// The line below has potential bug, needs improvement.
textarea.innerHTML = Transpile(element.outerHTML.replace(/(?!".*)\'(?!.*")/g, "\\'"), config, $scopes)

return new Function('$element', '$scopes',`
var $data = this;
Expand All @@ -25,9 +25,11 @@ export default function Template(element, $scopes) {
}
with( $data ){
var output = '${textarea.value.replace(/\n/g, '')
var output = '${textarea.value
.replace(/\n/g, '')
.replace(/<%=(.+?)%>/g, `'+safe(function(){return $1;})+'`)
.replace(/<%(.+?)%>/g, `';$1\noutput+='`)}'
.replace(/<%(.+?)%>/g, `';$1\noutput+='`)
}'
return output
}
`)
Expand Down
2 changes: 0 additions & 2 deletions src/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ export default function Transpile(html, config, $scopes) {
const regexTags = new RegExp(`\\${config.tags[0]}(.+?)\\${config.tags[1]}`, 'g')
const virtual = parser.parseFromString(html.replace(/<\/?template[^>]*>/g, ''), 'text/html')

virtual.documentElement.innerHTML = html.replace(/<\/?template[^>]*>/g, '')

virtual.querySelectorAll('[html-for], [html-if], [html-inner], [html-class]').forEach((element) => {

const htmlForeach = element.getAttribute('html-foreach')
Expand Down

0 comments on commit c4ef784

Please sign in to comment.