Triply-Dev / YASGUI.YASQE-deprecated

Deprecated, see https://github.com/TriplyDB/Yasgui for the Yasgui monorepo
MIT License
73 stars 36 forks source link

Parser error: Adding some strings at the beginning of the editor makes it crash #140

Closed bjonnh closed 4 years ago

bjonnh commented 5 years ago

Try running yasqe.replaceSelection("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")

when the cursor is on the first line (using the Firefox inspector on the Yasqe webpage I can reproduce that 100% of the time).

Selection become impossible and the editor is stuck.

bjonnh commented 5 years ago

yasqe.replaceSelection("http://x#") is a problem too. but it seems that http:# is not

bjonnh commented 5 years ago

Running a waterfall analysis shows that it seems to be stuck in : function findFirstPrefix(cm, line, ch, lineText) {…}

bjonnh commented 5 years ago

function findFirstPrefix(cm, line, ch, lineText) {
    console.log("Step 01")
  if (!ch) ch = 0;
  if (!lineText) lineText = cm.getLine(line);
    console.log("Step 02")
  lineText = lineText.toUpperCase();
  for (var at = ch, pass = 0; ; ) {
    var found = lineText.indexOf(lookFor, at);
    if (found == -1) {
      //no prefix on this line
      if (pass == 1) break;
      pass = 1;
      at = lineText.length;
      continue;
    }
    console.log("Step 03 pass: "+ pass + " found: " + found + " ch: "+ch + "lineText: " +lineText + "lookFor:" + lookFor)
    if (pass == 1 && found < ch) break;
    var tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
      console.log("Step 04 token type: " +tokenType)
    if (!/^(comment|string)/.test(tokenType)) return found + 1;
    at = found - 1;
      console.log("Step 05 at is now "+at)
    //Could not find a prefix, no use looping any further. Probably invalid query
    if (at === pass) break;
  }
}```

It is looping doing:
Step 03 pass: 0 found: 47 ch: 0 lineText: HTTP://WWW.W3.ORG/1999/02/22-RDF-SYNTAX-NS#TYPEPREFIX RDFS: <HTTP://WWWRDF-SCHEMA#> lookFor:PREFIX
Step 04 token type: comment prefixFold.js:34
Step 05 at is now 46 prefixFold.js:37 
LaurensRietveld commented 4 years ago

Fixed by PR #141 and also not an issue in the newest release (see https://github.com/TriplyDB/Yasgui)