1 new commit in galaxy-central:
https://bitbucket.org/galaxy/galaxy-central/changeset/cdbee5bc4a6d/ changeset: cdbee5bc4a6d user: greg date: 2012-12-03 15:31:52 summary: Clean up page content rendering in the tool shed. affected #: 7 files
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 lib/galaxy/util/shed_util_common.py --- a/lib/galaxy/util/shed_util_common.py +++ b/lib/galaxy/util/shed_util_common.py @@ -19,6 +19,9 @@ from elementtree import ElementTree, ElementInclude from elementtree.ElementTree import Element, SubElement
+eggs.require( 'markupsafe' ) +import markupsafe + log = logging.getLogger( __name__ )
INITIAL_CHANGELOG_HASH = '000000000000' @@ -1155,20 +1158,20 @@ return all_repository_dependencies def get_repository_file_contents( file_path ): if is_gzip( file_path ): - safe_str = to_safe_str( '\ngzip compressed file\n' ) + safe_str = to_safe_string( '\ngzip compressed file\n' ) elif is_bz2( file_path ): - safe_str = to_safe_str( '\nbz2 compressed file\n' ) + safe_str = to_safe_string( '\nbz2 compressed file\n' ) elif check_zip( file_path ): - safe_str = to_safe_str( '\nzip compressed file\n' ) + safe_str = to_safe_string( '\nzip compressed file\n' ) elif check_binary( file_path ): - safe_str = to_safe_str( '\nBinary file\n' ) + safe_str = to_safe_string( '\nBinary file\n' ) else: safe_str = '' for i, line in enumerate( open( file_path ) ): - safe_str = '%s%s' % ( safe_str, to_safe_str( line ) ) + safe_str = '%s%s' % ( safe_str, to_safe_string( line ) ) if len( safe_str ) > MAX_CONTENT_SIZE: large_str = '\nFile contents truncated because file size is larger than maximum viewing size of %s\n' % util.nice_size( MAX_CONTENT_SIZE ) - safe_str = '%s%s' % ( safe_str, to_safe_str( large_str ) ) + safe_str = '%s%s' % ( safe_str, to_safe_string( large_str ) ) break return safe_str def get_repository_files( trans, folder_path ): @@ -1631,7 +1634,7 @@ except: file_name = fpath return file_name -def to_safe_str( text, to_html=True ): +def to_safe_string( text, to_html=True ): """Translates the characters in text to an html string""" translated = [] for c in text: @@ -1639,25 +1642,29 @@ translated.append( c ) elif c in MAPPED_CHARS: translated.append( MAPPED_CHARS[ c ] ) - elif c in [ '\n', '\r' ]: + elif c in [ '\n' ]: if to_html: translated.append( '<br/>' ) else: translated.append( c ) + elif c in [ '\r' ]: + continue elif c in [ ' ', ' ' ]: translated.append( c ) else: translated.append( '' ) + if to_html: + str( markupsafe.escape( ''.join( translated ) ) ) return ''.join( translated ) def tool_shed_is_this_tool_shed( toolshed_base_url ): return toolshed_base_url.rstrip( '/' ) == str( url_for( '/', qualified=True ) ).rstrip( '/' ) def translate_string( raw_text, to_html=True ): if raw_text: if len( raw_text ) <= MAX_CONTENT_SIZE: - translated_string = to_safe_str( raw_text, to_html=to_html ) + translated_string = to_safe_string( raw_text, to_html=to_html ) else: large_str = '\nFile contents truncated because file size is larger than maximum viewing size of %s\n' % util.nice_size( MAX_CONTENT_SIZE ) - translated_string = to_safe_str( '%s%s' % ( raw_text[ 0:MAX_CONTENT_SIZE ], large_str ), to_html=to_html ) + translated_string = to_safe_string( '%s%s' % ( raw_text[ 0:MAX_CONTENT_SIZE ], large_str ), to_html=to_html ) else: translated_string = '' return translated_string
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 lib/galaxy/webapps/community/controllers/repository.py --- a/lib/galaxy/webapps/community/controllers/repository.py +++ b/lib/galaxy/webapps/community/controllers/repository.py @@ -2263,17 +2263,6 @@ if list: return ','.join( list ) return '' - def to_html_escaped( self, text ): - """Translates the characters in text to html values""" - translated = [] - for c in text: - if c in [ '\r\n', '\n', ' ', '\t' ] or c in VALID_CHARS: - translated.append( c ) - elif c in MAPPED_CHARS: - translated.append( MAPPED_CHARS[ c ] ) - else: - translated.append( '' ) - return ''.join( translated ) def __validate_repository_name( self, name, user ): # Repository names must be unique for each user, must be at least four characters # in length and must contain only lower-case letters, numbers, and the '_' character. @@ -2347,7 +2336,7 @@ anchors = modified + added + removed + deleted + unknown + ignored + clean diffs = [] for diff in patch.diff( repo, node1=ctx_parent.node(), node2=ctx.node() ): - diffs.append( self.to_html_escaped( diff ) ) + diffs.append( to_safe_string( diff, to_html=True ) ) is_malicious = changeset_is_malicious( trans, id, repository.tip( trans.app ) ) metadata = self.get_metadata( trans, id, ctx_str ) return trans.fill_template( '/webapps/community/repository/view_changeset.mako',
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 templates/webapps/community/common/common.mako --- a/templates/webapps/community/common/common.mako +++ b/templates/webapps/community/common/common.mako @@ -31,16 +31,6 @@ </script></%def>
-<%def name="escape_html_add_breaks( value )"> - <% - from galaxy import eggs - eggs.require('markupsafe') - import markupsafe - value = str( markupsafe.escape( value ) ).replace( '\n', '<br/>' ) - %> - ${value} -</%def> - <%def name="render_star_rating( name, rating, disabled=False )"><% if disabled: @@ -71,7 +61,7 @@ <div class="form-row"><label>Detailed description:</label><table id="description_table"> - <tr><td>${ escape_html_add_breaks( description_text ) }</td></tr> + <tr><td>${description_text}</td></tr></table><div style="clear: both"></div></div>
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 templates/webapps/community/repository/common.mako --- a/templates/webapps/community/repository/common.mako +++ b/templates/webapps/community/repository/common.mako @@ -1,4 +1,3 @@ -<%namespace file="/webapps/community/common/common.mako" import="escape_html_add_breaks" /><%def name="common_javascripts(repository)"><script type="text/javascript"> @@ -316,14 +315,17 @@ </%def><%def name="render_readme( readme, pad, parent, row_counter )"> - <% encoded_id = trans.security.encode_id( readme.id ) %> + <% + from galaxy.util.shed_util_common import to_safe_string + encoded_id = trans.security.encode_id( readme.id ) + %><tr class="datasetRow" %if parent is not None: parent="${parent}" %endif id="libraryItem-${encoded_id}"><td style="padding-left: ${pad+20}px;"> - ${escape_html_add_breaks( readme.text )} + ${ to_safe_string( readme.text, to_html=True ) } </td></tr><%
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 templates/webapps/community/repository/view_changeset.mako --- a/templates/webapps/community/repository/view_changeset.mako +++ b/templates/webapps/community/repository/view_changeset.mako @@ -185,7 +185,7 @@ ctr += 1 %><tr><td bgcolor="#E0E0E0">${anchor_str}</td></tr> - <tr><td>${ escape_html_add_breaks( diff ) }</td></tr> + <tr><td>${diff}</td></tr> %endfor </table></div>
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 templates/webapps/community/repository/view_repository.mako --- a/templates/webapps/community/repository/view_repository.mako +++ b/templates/webapps/community/repository/view_repository.mako @@ -5,6 +5,7 @@
<% from galaxy.web.framework.helpers import time_ago + from galaxy.util.shed_util_common import to_safe_string
has_readme = metadata and 'readme' in metadata has_metadata = repository.metadata_revisions @@ -157,7 +158,7 @@ ${repository.description | h} </div> %if repository.long_description: - ${render_long_description( repository.long_description )} + ${render_long_description( to_safe_string( repository.long_description, to_html=True ) )} %endif <div class="form-row"><label>Revision:</label>
diff -r 20a25a4f989d034c6be371ffa90947c8dc0269d3 -r cdbee5bc4a6d2140401ba0ab1ce7de3e9b9882b0 templates/webapps/community/repository_review/browse_review.mako --- a/templates/webapps/community/repository_review/browse_review.mako +++ b/templates/webapps/community/repository_review/browse_review.mako @@ -5,6 +5,7 @@ <% from galaxy.web.form_builder import CheckboxField from galaxy.webapps.community.util.container_util import STRSEP + from galaxy.util.shed_util_common import to_safe_string can_manage_repository = is_admin or repository.user == trans.user %>
@@ -93,7 +94,7 @@ <tr><td><div overflow-wrap:normal;overflow:hidden;word-break:keep-all;word-wrap:break-word;line-break:strict;> - ${ escape_html_add_breaks( component_review.comment ) } + ${ to_safe_string( component_review.comment, to_html=True ) } </div></td></tr>
Repository URL: https://bitbucket.org/galaxy/galaxy-central/
--
This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
galaxy-commits@lists.galaxyproject.org