WeBWorK Main Forum

Problem with image files/graphs

Problem with image files/graphs

by Nathan Wodarz -
Number of replies: 4
My students have been having problems seeing graphs and images on their assignments. I have traced the problem to their user names: I am using their full email addresses as user names, and there seems to be a problem with the @ symbol in the user name.

In particular, although WW tries to give images a name that includes the user name, browsers don't seem to like the @ in the name. For example, if a student had email/username nwoda999@uwsp.edu, an image name may show up in the address bar as nwoda999-Q-edu-2170-setSet_01prob1image1.png (i.e., missing the "@uwsp" part of the name). This results in a 404 error.

I've been able to get a workaround for graphs by searching $graph->gifName() for the "@" symbol and deleting it, but I can't seem to do this for static images. Does anyone have an idea?
In reply to Nathan Wodarz

Re: Problem with image files/graphs

by Michael Gage -
Hi Nathan,

I can't do it this instant (maybe over this weekend) but the place to fix this is probably in the alias() macro which is either in PGcore.pm (if you have that module) or in its earlier location in dangerousMacros.pl

In order to make unique names for auxiliary objects such as pictures (or links to those pictures) the name is constructed from the user name, the set name and the problem number (and maybe more). I think some sort of substitution in which @ is replaced by _ (or _at_ if you prefer) in every name constructed by alias() would solve the problem. This subroutine is the only place where you should have to make the change (I hope).

I'm glad to hear that otherwise user names which are complete email addresses are working ok in WeBWorK. It's a natural way to get unique login names for the users.

If you get to this first and find a fix that works please email it to me (gage at math.rochester.edu) and I'll put it in PGcore.pm in the svn repository.

Thanks.

-- Mike

In reply to Nathan Wodarz

Re: Problem with image files/graphs

by Sam Hathaway -
Since the "uwsp" part is disappearing too, I think the user ID might be getting evaluated in a double-quoted string at some point and Perl thinks it's a list ("@uwsp"). I'm hazy on the details, but isn't there a place where WW does an eval STRING to set the various envir values? If you have PG output the username does it get it right or do you get "nwoda999.edu"?
In reply to Sam Hathaway

Re: Problem with image files/graphs

by Michael Gage -
I think you got this right Sam. I've resolved this issue by making a minor change in PGgraphmacros.pl and one in PGalias.pm for good measure. Currently the changes are in the system/branches/gage_dev branch of the svn

in PGalias.pm:
+ $uniqIDstub =~ tr/@.,/___/; # replace @ . and , by _ since they don't work well in file names

-- the uniqueID stub is used as a base to provide url paths to some auxiliary files
-- this replaces all occurrences of @, . and , by _ There is some danger that the resulting stub is less unique than it was, but even the original choice was not guaranteed to be unique except that in practice it usually was. :-)

in PGgraphmacros.pl; -- which also tries to generate unique names:

$studentLogin =~ s/Q/QQ/g;
$studentLogin =~ s/\./-Q-/g;
+ $studentLogin =~ s/\,/-Q-/g;
+ $studentLogin =~ s/\@/-Q-/g;

The replacement of . was already in the subroutine. I added @ and the comma for good measure.

Improvements to the current situation would be to perform
some code refactoring in these two files and a more scientific method of generating a unique ID. There are also other places in the code base that generate unique names and these should be included in the refactoring. The unique names usually include the psvn (problem set version number) automatically generated by the set_user record, so searching for that string will help find the files involved.

After some further testing this and other updates will be moved to the trunk version of the svn but you can make these modifications now in your copies of the PGalias.pm and PGgraphmacros.pl files if you wish.

http://webwork.maa.org/viewvc/system/branches/gage_dev/pg/macros/PGgraphmacros.pl?sortby=date&view=log

and
http://webwork.maa.org/viewvc/system/branches/gage_dev/pg/lib/PGalias.pm?sortby=date&view=log

revision 6433 in both cases.




In reply to Michael Gage

Re: Problem with image files/graphs

by Sam Hathaway -
You could switch to giving files randomly-generated names. It's not as helpful when debugging but way less of a hassle to code and less risk of issues like this one. I've been using UUIDs lately.
-sam