jasonelle-archive / jasonelle-v2

🛸 🏘️ Jasonelle issues, releases, discussions and wiki repository.
https://jasonelle.com
Mozilla Public License 2.0
422 stars 58 forks source link

Problem with templates => body => background => html => text #81

Open leancode opened 4 years ago

leancode commented 4 years ago

Describe the bug Yesterday a russian member of the community posted a question on telegram and I tried to figure it out.

His objective was to use an html site as a background and alert the user whenever there was no network activity.

I found that there appears to be a bug whereby using templates => body => background => html => text instead of url does not render correctly.

I was attempting to accomplish this by using $network.request and catch the network error, and render the downloaded html on success. Since this needs a template, I could no longer use background => url but was using background => text. It seems that background => text sanitises the output rendered in some way (maybe this is intentional, but then it appears to serve no purpose as the $render already specifies the type - there should be at least a background "raw" paramenter if this is indeed on purpose).

In the examples below I stripped out all the JSON code irrelevant to the actual bug for the sake of brevity.

Example Jasonette Document URLs & JSON files

I created 3 apps to demonstrate this problem:

1) The first one is to show what the expected result would be: https://raw.githubusercontent.com/opsarl/jasonelle/master/bug-report-ok.json

{
  "$jason": {
    "head": {
      "actions": {
        "$load": {
          "type": "$render",
        }
      },
      "templates": {
        "body": {
          "background": {
            "type": "html",
            "url": "https://www.google.com",
            "action": {
              "type": "$default"
            }
          }
        }
      }
    }
  }
}

The result is this: Image of expected result

2) This is what the result is when text is used instead of url: https://raw.githubusercontent.com/opsarl/jasonelle/master/but-report-error.json

{
  "$jason": {
    "head": {
      "actions": {
        "$load": {
          "type": "$network.request",
          "options": {
            "url": "https://www.google.com",
            "data_type": "html",
            "timeout": "1"
          },
          "success": {
            "type": "$render",
            "option": {
              "type": "html"
            }
          }
        }
      },
      "templates": {
        "body": {
          "background": {
            "type": "html",
            "text": "{{$jason}}",
            "action": {
              "type": "$default"
            }
          }
        }
      }
    }
  }
}

The result is this: Image of erroneous result

This was also tried with any and all combinations of "data_type": using "raw" etc. with any $render types to no avail.

3) The I made a last app to dump the output of $jason during the render to ensure that the $jason was correctly populated and sent to the template.

https://raw.githubusercontent.com/opsarl/jasonelle/master/bug-report-text.json

{
  "$jason": {
    "head": {
      "actions": {
        "$load": {
          "type": "$network.request",
          "options": {
            "url": "https://www.google.com",
            "data_type": "raw",
            "timeout": "1"
          },
          "success": {
            "type": "$render",
          }
        }
      },
      "templates": {
        "body": {
          "background": {
            "type": "html",
            "text": "<html><head></head><body><pre>{{$jason.replace(/</g, '&lt').replace(/>/g,'&gt')}}</pre></body></html>",
            "action": {
              "type": "$default"
            }
          }
        }
      }
    }
  }
}

The result is this: Image of erroneous result

To Reproduce Run each app listed above.

Expected behavior background => html => text should simply render the content of the "text" option so it looks like example 1).

Screenshots See above.

Smartphone (please complete the following information):

Compilation:

Additional context Please see "Describe the bug" for context.

I would appreciate any workaround or idea on how to fix. I read through the source code to attempt to find the problem and it may be in JasonViewController.m. Unfortunately I am not an Objective-C expert or I would attempt to provide a fix. I could not find where the html is lost in translation exactly but it seems like it gets lost right in the end.