Removing an <element> from a string. (It seems to have no problem with a <script>, but <style> is being problematic.)

K.V.
  <function name="RemoveElement" parameters="element, string" type="string"><![CDATA[
    tagStart = Instr(string,"<"+element+">")
    lengthOfTag = Instr(tagStart, string,"</"+element+">")
    element = Mid(string,tagStart,lengthOfTag)
    stripped = Replace(string,element,"")
    return (stripped)
  ]]></function>

  one = "<p>Hello.</p><script>addTextAndScroll('Hello from script element!');</script>"
  two = "<style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>"
  msg (one)
  oneStripped = RemoveElement("script",one)
  msg (oneStripped)
  // The style doesn't work (probably because of the {} replacements).
  msg (two)
  // The next line will not be what I planned
  msg (RemoveElement("style",two))
  twoStrippedScript = RemoveElement("script",two)
  msg(twoStrippedScript)
  // The next line will not be what I planned
  msg (RemoveElement("style",twoStrippedScript))

image


NOTE: I need to set the altered string to an attribute on an in-game object without using any ASLEvent()s.


The problem with stuff like this is that printing to screen messes up what you see so much. Here is an alternative version of the function:

  <function name="RemoveElement" parameters="element, string" type="string"><![CDATA[
    elementStart = Instr(string, "<" + element)
    if (elementStart > 0) {
      elementEnd = Instr(elementStart, string,"</"+element+">") + 3 + LengthOf(element)
      element = Mid(string, elementStart, elementEnd - elementStart)
      stripped = Replace(string, element, "")
      return (stripped)
    }
    else {
      return (string)
    }
  ]]></function>

I tested it with:

      msg ("---------------------------------------------------")
      one = "<tag>Hello.</tag><other att=\"fjgg\">addTextAndScroll('Hello from script element!');</other>"
      msg (one)
      msg ("---------------------------------------------------")
      msg (RemoveElement("tag",one))
      msg ("---------------------------------------------------")
      msg (RemoveElement("other",one))
      msg ("---------------------------------------------------")

Changing the tags to script or style will not change how the function works, so that should be fine. However, it may well affect what you see.


lengthOfTag = Instr(tagStart, string,"</"+element+">")

As far as I can tell, this doesn't give you the length of the tag. It gives the number of characters in the string before the </element>.

tagEnd = Instr(tagStart, string,"</"+element+">") - number of characters before the closing tag
lengthOfTag = tagEnd - tagStart - length, excluding the closing tag
lengthOfTag = lengthOfTag + LengthOf("</"+element+">") - or just LengthOf(element)+3

The function as you had it would leave the ending tag if your element is at the start of the string; but capture 2 extra characters for every character before the element. So it will work correctly only if the number of characters before the element equals the length of the ending tag; or if the element is at the end of the string (as in your script example).


Though if you're using this on arbitrary bits of HTML strings (rather than code you provided), remember that the opening tag may contain attributes, and the closing tag is permitted spaces; </style > is valid. As is <script />.

So...

<function name="RemoveElement" parameters="element, string" type="string"><![CDATA[
  startPos = Instr (string, "<"+element)
  if (startPos = 0) {
    return (string)
  }
  endPos = Instr (startPos, string, ">")
  if (endPos = 0) {
    error ("Element doesn't terminate")
  }
  if (Mid (string, endPos-1, 1) = "/") {
    endPos = endPos + 1
  }
  else {
    endPos = Instr (endPos, string, "</"+element)
    if (endPos = 0) {
      error ("No closing tag!")
    }
    endPos = Instr (endPos + LengthOf(element), string, ">")
    if (endPos = 0) {
      error ("Closing tag doesn't terminate!")
    }
    endPos = endPos + 1
  }
  return Left (string, startPos) + Right (string, LengthOf(string) - endPos
</function>

(Used Left and Right rather than Mid and Replace; because string searches are slow. In this case, the difference probably isn't much, but Replace is still checking every character of the string to see if the element is there, when you already know what character number it starts at)

(and yes, this will still get confused if you have an attribute that contains XML; or nested elements of the same type. But it's a little more robust)


K.V.

Thanks, guys!

I'll test these out.


I guess I could have mentioned that I'm saving the string as plain text in the end.

When I don't remove the <script> elements and use var plainText = $("#whatever").text(), string "one" is this:

Hello.addTextAndScroll('Hello from script element!');

...but after I strip it (using the code I posted):

Hello.

This is how I'm testing it (with a JS.alert()):

one = "<div id='test-stuff'><p>Hello.</p><script>addTextAndScroll('Hello from script element!');</script></div>"
//two = "<style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>"
msg (one)
msg("<hr/>")
oneStripped = RemoveElement("script",one)
msg("<div id='test-again'>"+oneStripped+"</div>")
JS.eval("var txtToShow = $('#test-stuff').text();alert(txtToShow);var strippedTxt = $('#test-again').text();alert(strippedTxt);")


image
image
image


If you're using the one I posted, might be worth noting that to remove all instances of a particular element (rather than just the first) from a string, you could change the last line to:
return (Left (string, startPos) + RemoveElement (element, Right (string, LengthOf(string) - endPos)))

And yes, I know I missed out the brackets from the return statement in the last post. I've been writing Perl again the last couple of days.


K.V.

Trying to go by the character count let something slip by, no matter what I tried.

I've got some regex going on now:

regEx = "(?<text><(|.+|\\s+)script(|.+|\\s+)>(|.+|\\s+)<(|.+|\\s+)/script(|\\s+)>)"
//
player.this = "Text here.<script>alert('hello');</script>"
//msg (IsRegexMatch(regEx,player.this))
player.thisdict = NewDictionary()
player.thisdict = Populate(regEx,player.this)
player.thistxt = DictionaryItem(player.thisdict,"text")
player.newthis = Replace(player.this,player.thistxt,"")
//JS.alert(player.thistxt)
//JS.alert(player.newthis)
//
player.that = "<script onerror='alert('ti');>console.log('Hey you');</script ><p>I am a paragraph!</p>"
//msg (IsRegexMatch(regEx,player.that))
player.thatdict = NewDictionary()
player.thatdict = Populate(regEx,player.that)
player.thattxt = DictionaryItem(player.thatdict,"text")
player.newthat = Replace(player.that,player.thattxt,"")
//JS.alert(player.thattxt)
//JS.aler(player.newthat)

image


What did I overlook?

(I always overlook something...)


Try it on this string: Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);</script><p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert("Here's another script!");</script>...<p>I think I missed something just now</p>

:)


K.V.

Testing now...

Changing this to single quotes: alert('Here's another script!')

Be right back...


K.V.

image

Curses!!!


K.V.

Oh, that's dirty!!! (Which is what I was hoping for!)

I fixed it a third of the way. (Still working.)

regEx = "(?<text><(|\\s+)script(|.+|\\s+)>(|.+|\\s+)<(|.+|\\s+)/script(|\\s+)>)"
dict = NewDictionary()
dict = Populate(regEx,data)
snippet = DictionaryItem(dict,"text")
player.tempSnippet = snippet
result = Replace(data,snippet,"")
return (result)

image


K.V.

That was pretty good, mrangel!

image

image

regEx = "(?<text><(|\\s+)script(|.+|\\s+)>(|.+|\\s+)<(|.+|\\s+)/script(|\\s+)>)"
Log ("Stripping:")
Log (data)
dataList = NewStringList()
newdataList = NewStringList()
dataList = Split(data,"/script")
foreach (o, dataList) {
  Log("Running foreach")
  Log(o)
  if (EndsWith(o,"<")) {
    o = o + "/script>"
  }
  if (EndsWith(o,"< ")) {
    o = o + " /script>"
  }
  if (StartsWith(o," >")) {
    o = Right(o,LengthOf(o)-2)
  }
  if (StartsWith(o,">")) {
    o = Right(o,LengthOf(o)-1)
  }
  Log ("Processing:")
  Log (o)
  if (IsRegexMatch(regEx,o)) {
    Log ("FOUND MATCH:")
    dict = NewDictionary()
    dict = Populate(regEx,o)
    snippet = DictionaryItem(dict,"text")
    Log ("Removing:")
    Log (snippet)
    o = Replace(o,snippet,"")
    Log ("Stripped result:")
    Log (o)
    list add(newdataList,o)
  }
  else {
    Log ("NO MATCH")
    list add(newdataList,o)
  }
}
newdata = ""
if (ListCount(newdataList)>0) {
  data = Join(newdataList,"")
  Log("Joined result:")
  Log(data)
}
Log ("RETURNING:")
Log (data)
return (data)

K.V.

jQuery is much easier (but each ASLEvent() ends a turn (and calls the turn scripts and all that)):

function stripScript(){
	var gameContent = $("#divOutput").html();
	alert("Stripping script elements from: \n\n"+gameContent);
	$("#transcript-content").html(gameContent);
	$("#transcript-content").find('script').remove();
        // TODO: Replace <br> with "\n", and  \
        //    add "\n" at the beginning and end of each header and <p>!!!
        //
        //  It's easy (now that I've learned how from MrAngel), \
        //      I just haven't done it yet.
        //
	//var txt = $("#transcript-content").text();
        //  Just displaying as HTML for now.
	var txt = $("#transcript-content").html();
	txt = "Stripped: " + txt;
	alert(txt);
	$("#transcript-content").html(txt);
	$("#transcript-content").show();
	addLogEntry(txt);
};

image


Trying to go by the character count let something slip by, no matter what I tried.

What did my one miss? I'm scripting on my phone off the top of my head, while my laptop prepares a new book, so didn't actually test it.


K.V.

What did my one miss?

player.this = "Text here.<script>alert('hello');</script>"
player.newthis = StripScriptElement(player.this)
player.that = "<script onerror='alert('ti');>console.log('Hey you');</script ><p>I am a paragraph!</p>"
player.newthat = StripScriptElement(player.that)
player.mrangelstext = "Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);</script><p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert('Here's another script!');</script>...<p>I think I missed something just now</p>"
msg (player.mrangelstext)
player.newmrangelstext = RemoveElement("script",player.mrangelstext)
msg (player.newmrangelstext)

image

image


player.styleelement = "<style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>"
msg (player.styleelement)
player.styleelement2 = RemoveElement("script",player.styleelement)
msg (player.styleelement2)
player.styleelement3 = RemoveElement("style",player.styleelement2)
msg (player.styleelement3)

image
image


K.V.

That last script I posted seems to catch everything.

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Strip the Scripts">
    <gameid>32998548-63f8-4e13-ae49-8dc5afc3bd28</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <enter type="script"><![CDATA[
      player.mrangelstext = "Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);</script><p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert('Here's another script!');</script>...<p>I think I missed something just now</p>"
      msg (player.mrangelstext)
      player.newmrangelstext = StripHTMLElement("script",player.mrangelstext)
      msg (player.newmrangelstext)
      player.two = "<style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>"
      msg (player.two)
      player.twoStrippedScript = StripHTMLElement("script",player.two)
      msg (player.twoStrippedScript)
      player.newtwo = StripHTMLElement("style",player.twoStrippedScript)
      msg (player.newtwo)
    ]]></enter>
    <beforeenter type="script"><![CDATA[
       player.this = "Text here.<script>alert('hello');</script>"
       player.newthis = StripHTMLElement("script",player.this)
       player.that = "<script onerror='alert('ti');>console.log('Hey you');</script ><p>I am a paragraph!</p>"
      player.newthat = StripHTMLElement("script",player.that)
    ]]></beforeenter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="StripHTMLElement" parameters="element, data" type="string"><![CDATA[
    regEx = "(?<text><(|\\s+)"+element+"(|.+|\\s+)>(|.+|\\s+)<(|.+|\\s+)/"+element+"(|\\s+)>)"
    Log ("Stripping:")
    Log (data)
    dataList = NewStringList()
    newdataList = NewStringList()
    dataList = Split(data,"/"+element+"")
    foreach (o, dataList) {
      Log ("Running foreach")
      Log (o)
      if (EndsWith(o,"<")) {
        o = o + "/"+element+">"
      }
      if (EndsWith(o,"< ")) {
        o = o + " /"+element+">"
      }
      if (StartsWith(o," >")) {
        o = Right(o,LengthOf(o)-2)
      }
      if (StartsWith(o,">")) {
        o = Right(o,LengthOf(o)-1)
      }
      Log ("Processing:")
      Log (o)
      if (IsRegexMatch(regEx,o)) {
        Log ("FOUND MATCH:")
        dict = NewDictionary()
        dict = Populate(regEx,o)
        snippet = DictionaryItem(dict,"text")
        Log ("Removing:")
        Log (snippet)
        o = Replace(o,snippet,"")
        Log ("Stripped result:")
        Log (o)
        list add (newdataList, o)
      }
      else {
        Log ("NO MATCH")
        list add (newdataList, o)
      }
    }
    newdata = ""
    if (ListCount(newdataList)>0) {
      data = Join(newdataList,"")
      Log ("Joined result:")
      Log (data)
    }
    Log ("RETURNING:")
    Log (data)
    return (data)
  ]]></function>
</asl>

image


image


1/30/2018 12:27:08 PM Stripping:
1/30/2018 12:27:08 PM Text here.<script>alert('hello');</script>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM Text here.<script>alert('hello');<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM Text here.<script>alert('hello');</script>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <script>alert('hello');</script>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM Text here.
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM >
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM 
1/30/2018 12:27:08 PM NO MATCH
1/30/2018 12:27:08 PM Joined result:
1/30/2018 12:27:08 PM Text here.
1/30/2018 12:27:08 PM RETURNING:
1/30/2018 12:27:08 PM Text here.
1/30/2018 12:27:08 PM Stripping:
1/30/2018 12:27:08 PM <script onerror='alert('ti');>console.log('Hey you');</script ><p>I am a paragraph!</p>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM <script onerror='alert('ti');>console.log('Hey you');<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <script onerror='alert('ti');>console.log('Hey you');</script>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <script onerror='alert('ti');>console.log('Hey you');</script>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM 
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM  ><p>I am a paragraph!</p>
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <p>I am a paragraph!</p>
1/30/2018 12:27:08 PM NO MATCH
1/30/2018 12:27:08 PM Joined result:
1/30/2018 12:27:08 PM <p>I am a paragraph!</p>
1/30/2018 12:27:08 PM RETURNING:
1/30/2018 12:27:08 PM <p>I am a paragraph!</p>
1/30/2018 12:27:08 PM Stripping:
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);</script><p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert('Here's another script!');</script>...<p>I think I missed something just now</p>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1><script>$('h1').css(color: red);</script>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <script>$('h1').css(color: red);</script>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM ><p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert('Here's another script!');<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <p>Now who's talking?</p><h1>Do you expect this to work?</h1><script>alert('Here's another script!');</script>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <script>alert('Here's another script!');</script>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM <p>Now who's talking?</p><h1>Do you expect this to work?</h1>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM >...<p>I think I missed something just now</p>
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM ...<p>I think I missed something just now</p>
1/30/2018 12:27:08 PM NO MATCH
1/30/2018 12:27:08 PM Joined result:
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1><p>Now who's talking?</p><h1>Do you expect this to work?</h1>...<p>I think I missed something just now</p>
1/30/2018 12:27:08 PM RETURNING:
1/30/2018 12:27:08 PM Let's see how this works...<h1>Hahahahaha!</h1><p>Now who's talking?</p><h1>Do you expect this to work?</h1>...<p>I think I missed something just now</p>
1/30/2018 12:27:08 PM Stripping:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span><script>addTextAndScroll('<p>hello from script element!!!<p>');</script>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <script>addTextAndScroll('<p>hello from script element!!!<p>');</script>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM >
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM 
1/30/2018 12:27:08 PM NO MATCH
1/30/2018 12:27:08 PM Joined result:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM RETURNING:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM Stripping:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style><span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@<
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style>
1/30/2018 12:27:08 PM FOUND MATCH:
1/30/2018 12:27:08 PM Removing:
1/30/2018 12:27:08 PM <style>#test-p@@@open@@@color:green;font-weight:bold;@@@close@@@</style>
1/30/2018 12:27:08 PM Stripped result:
1/30/2018 12:27:08 PM 
1/30/2018 12:27:08 PM Running foreach
1/30/2018 12:27:08 PM ><span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM Processing:
1/30/2018 12:27:08 PM <span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM NO MATCH
1/30/2018 12:27:08 PM Joined result:
1/30/2018 12:27:08 PM <span id='test-p'>This is text with its own style element.</span>
1/30/2018 12:27:08 PM RETURNING:
1/30/2018 12:27:08 PM <span id='test-p'>This is text with its own style element.</span>

Writing script while half asleep is rarely a good idea :p
Looking at my script again, I seem to have missed that Instr works like the VB version of the function (the first character is 1, not 0).

What I meant was:

<function name="RemoveElement" parameters="element, string" type="string"><![CDATA[
  startPos = Instr (string, "<"+element)
  if (startPos = 0) {
    return (string)
  }
  endPos = Instr (startPos, string, ">")
  if (endPos = 0) {
    error ("Element doesn't terminate")
  }
  if (not Mid (string, endPos-1, 1) = "/") {
    endPos = Instr (endPos, string, "</"+element)
    if (endPos = 0) {
      error ("No closing tag!")
    }
    endPos = Instr (endPos + LengthOf(element), string, ">")
    if (endPos = 0) {
      error ("Closing tag doesn't terminate!")
    }
  }
  return (Left (string, startPos - 1) + RemoveElement (element, Right (string, LengthOf(string) - endPos)))
</function>

K.V.

(the first character is 1, not 0)

The same thing got me, but I had the luxury of being able to just run it through the desktop version of Quest.

(The web editor is NOT the version to just test random things out with! ERRORS GALORE! SCRIPTS DELETED! AARGH!!!)


I know that you (and HK) are just theorizing or sharing wisdom 99% of the time.

(Probably Pixie and XanMag, too.)

...and 99% of THOSE times, you hit the bulls-eye, so...

You guys are just bad-asses!

I don't think I've got a full year of using Quest (or programming at all) under my belt quite yet. I still have to try something out before I know if it will work.


K.V.

That last code you posted works perfectly, by the way.

Just had to close the CDATA out on that last line.

This appears to be the best solution:

<function name="RemoveElement" parameters="element, string" type="string"><![CDATA[
  startPos = Instr (string, "<"+element)
  if (startPos = 0) {
    return (string)
  }
  endPos = Instr (startPos, string, ">")
  if (endPos = 0) {
    error ("Element doesn't terminate")
  }
  if (not Mid (string, endPos-1, 1) = "/") {
    endPos = Instr (endPos, string, "</"+element)
    if (endPos = 0) {
      error ("No closing tag!")
    }
    endPos = Instr (endPos + LengthOf(element), string, ">")
    if (endPos = 0) {
      error ("Closing tag doesn't terminate!")
    }
  }
  return (Left (string, startPos - 1) + RemoveElement (element, Right (string, LengthOf(string) - endPos)))
]]></function>

K.V.

This gets past both of our scripts:

<css><![CDATA[<style type="text/css">div#txtCommandDiv {border:none; font-size:12pt; font-family:Georgia, serif; } input#txtCommand { outline:none; border:none; font-size:16px; margin:0; padding:0; }</style>
   
       <style type="text/css">
                 
        div#txtCommandDiv {
            border: none;
            background: no-repeat;
          }
          input#txtCommand {
            outline:none;
            border: none;
            margin:0;
            padding:0;
            max-width: 1000px;
          }
          #status { display: none !important; visibility: hidden !important; }       
          </style>
                                                                                                                                                                                                                                                                                                                                                                                    ]]></css>

...and it's in the turn script, so the output is this (with either of our Quest codes OR with jQuery's $(element).text()):


TRANSCRIPT:

   
       
                 
        div#txtCommandDiv {
            border: none;
            background: no-repeat;
          }
          input#txtCommand {
            outline:none;
            border: none;
            margin:0;
            padding:0;
            max-width: 1000px;
          }
          #status { display: none !important; visibility: hidden !important; }       
          
                                                                                                                                                                                                                                                                                                                                                                                    





   
       
                 
        div#txtCommandDiv {
            border: none;
            background: no-repeat;
          }
          input#txtCommand {
            outline:none;
            border: none;
            margin:0;
            padding:0;
            max-width: 1000px;
          }
          #status { display: none !important; visibility: hidden !important; }       
          
                                                                                                                                                                                                                                                                                                                                                                                    


   
       
                 
        div#txtCommandDiv {
            border: none;
            background: no-repeat;
          }
          input#txtCommand {
            outline:none;
            border: none;
            margin:0;
            padding:0;
            max-width: 1000px;
          }
          #status { display: none !important; visibility: hidden !important; }       
          
                                                                                                                                                                                                                                                                                                                                                                                    
It all started innocently enough...

   

K.V.

I just now saw the post with your function, Pixie!

It seems to be working!!!


K.V.

Oops...

Nope.

Well, it works too  good.

It removes the text after the <style> element, too.

  <object name="room">
    <inherit name="editor_room" />
    <enter type="script"><![CDATA[
      msg(player.kv_att)
    ]]></enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <attr name="kv_att"><![CDATA[
      
      <style>
      
        #divOutput *{
          color:green;
          background:lightgray;
        }
        
      </style>
      
      "Hello, there," says the old-timing man.  "You got any bourbon on  ya'?"
      <br/>
      "No, sir," you reply.  "Sure don't."
      <br/>
      And that's when you notice it.
      <br/>
      The double-quotes are not escaped in the source code!!!
      <br/>
      Well... At least there are line breaks now!
                                                ]]></attr>
    </object>
  </object>
  <function name="StripElement" parameters="element, string" type="string"><![CDATA[
    elementStart = Instr(string, "<" + element)
    if (elementStart > 0) {
      elementEnd = Instr(elementStart, string,"</"+element+">") + 3 + LengthOf(element)
      element = Mid(string, elementStart, elementEnd - elementStart)
      stripped = Replace(string, element, "")
      return (stripped)
    }
    else {
      return (string)
    }
  ]]></function>

image


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums