ID:98910
 
Resolved
BYOND Version:471
Operating System:Windows Vista Home Premium 64-bit
Web Browser:Chrome 5.0.375.99
Applies to:Website
Status: Resolved (web)

This issue has been resolved.
Descriptive Problem Summary:
When trying to use ImportText() on content retrieved from a world hub in text format for viewing medals one receives a BYOND Error.

Example: BYOND Error: failed to parse savefile text at line 606 (reading 'end of file'):

Numbered Steps to Reproduce Problem:
1) Try to ImportText() on the game's hub's medal data.

Code Snippet (if applicable) to Reproduce Problem:
var/request[] = world.Export("http://www.byond.com/games/[author]/[worldName]?command=view_medals&format=text&per_page=1&page=[page]")

error = _MDValidateContent(request)
if(error) return 0

var/content = file2text(request["CONTENT"])

if(content)
var/savefile/medalData = new()
if(medalData.ImportText("/", content) )
// Process data here.
else
world << "Failed to ImportText."

/*
The above outputs:
BYOND Error: failed to parse savefile text at line 12 (reading 'end of file'):
Failed to ImportText.
*/


proc
/*
Determines if data retrieved from the hub is valid.
*/

_MDValidateContent(var/request)
// If for some reason there is no return value for world.Export()
if(!request) return "No data received from BYOND Hub."

// Make sure that the request has been completed with the proper status.
if(request["STATUS"] != "200 OK") return "Bad HTTP status: [request["STATUS"]]"

// Finally, ensure that the content is in the form we requested.
var/list/contentType = params2list(request["CONTENT-TYPE"])
if(contentType && contentType[1] != "text/plain") return "Incorrect content type: [contentType[1]]"

return 0


Expected Results:ImportText() to function properly.

Actual Results: ERROR =D

Does the problem occur:
Every time? Or how often? Yes.
In other games? Yes..
In other user accounts? Yes...
On other computers? Yes....

When does the problem NOT occur?The problem is persistent.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.) Well, I can't back up to an older version of the website, soooo that portion is out. Since I think I know what the problem is I'm not going back to older versions of the BYOND suite for testing.

Workarounds: I think maybe removing a trailing newline in the content may work but I've yet to determine how that is possible.

My Findings:
Upon inspection of the file in question I noticed that as opposed to medals found by keys (My Medals) when pulling medals via hub (Medals for IainPeregrine.Regressia) the hub file has an additional trailing newline and I think this is causing ImportText to misinterpret the EOF.

The other thing I noticed, was that when these pages are saved as a .txt file, you'll see that they don't appear quite like they do in your browser. If you save one, and open it in your text editor you'll see that icon is a few tabs further in. I feel that this is the likelier of the two for causing the problem, but I thought I would bring the other up since it was reporting an EOF error. It appears that the icon setting isn't tabbed, but rather spaced into alignment.

Other notes:
It tends to happen no matter how many medals are pulled per_page, or which page data is pulled from.
This error does not occur for key medals.
I've been doing ImportText() on medal data for keys, I'd assume that repeating similar techniques here (on hubs) would work.

Try something like this
var/http[]=world.Export("http://www.byond.com/games/[author]/[worldName]?command=view_medals&format=text&per_page=1&page=[page]")
var/savefile/F=new
F.ImportText("/",file2text(http["CONTENT"]))
Ahh, excuse me. I've done that beforehand and just failed to display it. I'll update the above to demonstrate fully I suppose.