Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MF{type} toString() methods include carriage return #109

Open
splace opened this issue May 28, 2019 · 9 comments
Open

MF{type} toString() methods include carriage return #109

splace opened this issue May 28, 2019 · 9 comments

Comments

@splace
Copy link

splace commented May 28, 2019

example

#VRML V2.0 utf8 Titania V4.5.2

WorldInfo {
  title "print-bug"
}

DEF script Script {
  field          MFFloat  floatArray [1,2,3]
  eventOut       MFString floatArraytext

  url "ecmascript:

function initialize ()
{
	floatArraytext[0] = floatArray
}

"
  directOutput TRUE
}

Shape {
  appearance Appearance {
    material Material { }
  }
  geometry DEF display Text {
    string "default"
  }
}

ROUTE script.floatArraytext TO display.set_string

Screenshot from 2019-05-28 15:18:11

@create3000
Copy link
Owner

MF{type} toString() is a browser dependent method and not specified. Please do your own formatting, as you like it, manually.

For instance you could use:

function initialize ()
{
	floatArraytext [0] += "[";

	for (var i = 0; i < floatArray .length; ++ i)
		floatArraytext[0] += floatArray [i] + " ";

	floatArraytext [0] += "]";
}

@create3000
Copy link
Owner

create3000 commented May 29, 2019

Please note that Titania is now listed on Flathub and Snap Store. All new updates will be from there, the create3000 Flatpak will not longer be updated. Please follow the instructions from http://create3000.de/titania/download/.

@splace
Copy link
Author

splace commented May 29, 2019

Please do your own formatting, as you like it, manually.

this was found causing problems in an existing world, i am testing for compliance.

MF{type} toString() is a browser dependent method and not specified.

AFAIK it is specified for arrays in java/ecmascript to be comma separated.

and newlines don't appear to be being generated by the browser (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString )

are you sure this isn't being generated manually by x-ite's js engine? somewhere in the prototype chain directly coded for a 'pretty' print.

@splace
Copy link
Author

splace commented May 29, 2019

Please note that Titania is now listed on Flathub and Snap Store. All new updates will be from there, the create3000 Flatpak will not longer be updated. Please follow the instructions from http://create3000.de/titania/download/.

i had been wondering why updates had slowed.

@create3000
Copy link
Owner

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString describes the JavaScript 'Array' objects method toString.
An X3D MF* field is not derived from JavaScript 'Array' and has its own formating,

@splace
Copy link
Author

splace commented Jun 2, 2019

An X3D MF* field is not derived from JavaScript 'Array' and has its own formating,

i, personally, would see 'toString' as producing 'human readable' text and so would not make assumptions about what it produced, (other than that, when displayed to a human, they would be able to read the value of the object), but i would guess that browsers do generally derive MF*'s from JS Array's and so some people may have unfortunately relied on its formatting.

but, here, it was just being used to display a value for a human to read, using the only direct vrml way to do that, through a Text Node. the inclusion of non-printing control characters is what made this stand out as an issue. many other variations in the formatting of the string would not have been an issue.

@create3000
Copy link
Owner

create3000 commented Jun 3, 2019

i, personally, would see 'toString' as producing 'human readable' text

An MF* field produces human readable text if you use print (mffield) or Browser .print (mffield) for debugging purposes, but MF*.toString is not designed to send the output to a Text node, then you must do your own formatting.

@create3000
Copy link
Owner

create3000 commented Jun 3, 2019

It is no rocket science to get nice one line formatting, for instance you could do:

function initialize ()
{
	var a = new MFInt32 (1, 2, 3, 4, 5, 6);
	
	print (a .toString () .replace (/\s+/g, " "));
}

@splace
Copy link
Author

splace commented Jun 3, 2019

It is no rocket science to get nice one line formatting, for instance you could do:

thank you for explaining, again, how easy it is to bypass this issue by modifying the world. i am not making content, this is preexisting (the code in the OP is cut from), and if i were making some it would not be browser dependent.

An MF* field produces human readable text if you use print (mffield) or Browser .print (mffield) for debugging purposes, but MF*.toString is not designed to send the output to a Text node, then you must do your own formatting.

i had not realised that print() doesn't produce the same string as toString(), for me this goes against a very well established behaviour of js, the use of toString() for default string conversions.

it seems to me that this output is more appropriate to toSource(), as this is intended to produce parsable output (machine/human readability) where new lines are expected/handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants