Sdf Inline : from php to javascript formatting problem

User abe50b9859

24-09-2012 08:40:25

Hello,


I have a problem that occur for the moment on only one sdf, but i want to prevent any other failure.


Here is the simplified pipeline :



All the sdf i tried are well visualized but for the attached sdf, i just have the javascript error : SyntaxError : unterminated string literal.


Checking the source file of the webpage, mview param :


mview_param("mol","OpenBabel09201216583D
 
 177184 0 0 0 0 999 V2000
  0.3145 0.5369 -0.1327 C 0 0 1 0 0 0 0 0 0 0 0 0
  0.0658 -0.9712 -0.0654 C 0 0 1 0 0 0 0 0 0 0 0 0


...

94177 1 0 0 0 0
M END
$$$$");



is clearly different from working molecules :


mview_param("mol","\nmol\n\n 28 29  0  0  0  0  0  0  0  0999 V2000\n   -0.0172    1.4168    0.0098 S   0  0  0  0  0  0  0  0  0  0  0  0   \n    0.0021   -0.0041    0.0020 O   0  0  0  0  0  0  0  0  0  0  0  0   \n    1.1303    2.2549    0.0034 O   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.9070    1.8620   -1.3139 N   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.6806    4.1264   -0.7384 N   0  0  0  0  0  0  0  0  0  0  0  0   \n   -3.1097    2.9584    4.8238 N   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.9369    1.8752    1.4412 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.8324    0.9825    2.0009 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.7572    3.1248    2.0056 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.1569    3.2065   -1.5633 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.3807    2.5950    3.6892 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.5548    1.3386    3.1228 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.4761    3.4872    3.1277 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.9046    3.5735   -2.6772 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.1454    4.9152   -2.9136 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.6282    5.8478   -2.0246 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.8945    5.4128   -0.9389 C   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.2538    1.1845   -1.9154 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.9673    0.0058    1.5600 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.0537    3.8180    1.5685 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -3.2546    0.6412    3.5590 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.3351    4.4631    3.5682 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.2917    2.8214   -3.3487 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.7223    5.2300   -3.7706 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -3.7384    2.3331    5.2171 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -2.9873    3.8360    5.2184 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -1.7979    6.9029   -2.1809 H   0  0  0  0  0  0  0  0  0  0  0  0   \n   -0.4904    6.1349   -0.2449 H   0  0  0  0  0  0  0  0  0  0  0  0   \n  1  2  2  0  0  0  0\n  1  3  2  0  0  0  0\n  1  4  1  0  0  0  0\n  1  7  1  0  0  0  0\n  4 10  1  0  0  0  0\n  4 18  1  0  0  0  0\n  5 10  1  0  0  0  0\n  5 17  2  0  0  0  0\n  6 11  1  0  0  0  0\n  6 25  1  0  0  0  0\n  6 26  1  0  0  0  0\n  7  8  2  0  0  0  0\n  7  9  1  0  0  0  0\n  8 12  1  0  0  0  0\n  8 19  1  0  0  0  0\n  9 13  2  0  0  0  0\n  9 20  1  0  0  0  0\n 10 14  2  0  0  0  0\n 11 12  2  0  0  0  0\n 11 13  1  0  0  0  0\n 12 21  1  0  0  0  0\n 13 22  1  0  0  0  0\n 14 15  1  0  0  0  0\n 14 23  1  0  0  0  0\n 15 16  2  0  0  0  0\n 15 24  1  0  0  0  0\n 16 17  1  0  0  0  0\n 16 27  1  0  0  0  0\n 17 28  1  0  0  0  0\nM  END\n$$$$");


Here is the replace instructions i use to load the sdf files :


mview_param("mol","{{ item|replace({'\r\n':'\n','\r':'\\n','\r':'\n','\\':'\\\\','\n':'\\n','\"':'\\\"',"'":"\\'"}) }}");


I use TWIG as a template engine for php. Item is the variable containing the sdf.


Thank you for your help.

ChemAxon 5433b8e56b

25-09-2012 14:09:55

Hi,


as I see the file is correct, it has CRLF at the end of lines.


So the replace operation in this case does the following:
- relpace the CRLF with LF
- noop ("\r" : "\n")
- noop ("\r" : "\\n") I do not really understand this rule, the line before eliminated all the \r-s in the file
- noop ("\\" : "\\\\")
- replace LF with \\n (I assume this would make Twig to print the \n string into the html code.
- noop ("\"" : "\\\"")
- noop ("'" : "\\'")


noop means there is nothing to do with that rule in this file.


The basic instinct of mine is that the doubling of the slashes happens too early and that is why this case fails, but this seems an invalid tip, because the \r->\n conversion happens before the \r->\\n conversion so the second does nothing, and in this way, the \\->\\\\ has no effect on the \n-s that has been created from \r\n->\n and \r->\n since the \n is a placeholder for the line feed character that does not contain any \. So actually I have no clue, but I think you should do some debugging here (check the string value after every applied replace), and check your files that are working and this exception for differences in line ending characters.


I hope this helps, but the problem clearly is the formatting of the parameter value, the Javascript error is being thrown because of the invalid string, since Javascript does not support multiline strings.


Regards,
Istvan