@@ -119,8 +119,23 @@ private String rewritePrettyMappings(final String url)
119119
120120 List <UrlMapping > matches = new ArrayList <UrlMapping >();
121121
122- QueryString queryString = QueryString .build (strippedUrl );
123- String mappingId = queryString .getParameter ("com.ocpsoft.mappingId" );
122+ /*
123+ * First build an empty query string. We will add the parameters
124+ * only if the URL contains a ? character in the next step
125+ */
126+ final QueryString queryString = QueryString .build ("" );
127+
128+ /*
129+ * Try to identify the mapping for this URL. Remove the metadata
130+ * from the URL if it exists.
131+ */
132+ String mappingId = null ;
133+ if (strippedUrl .contains ("?" )) {
134+ queryString .addParameters (strippedUrl );
135+ mappingId = queryString .getParameter (REWRITE_MAPPING_ID_KEY );
136+ queryString .removeParameter (REWRITE_MAPPING_ID_KEY );
137+ }
138+
124139 if (mappingId != null )
125140 {
126141 matches .add (prettyConfig .getMappingById (mappingId ));
@@ -147,15 +162,7 @@ private String rewritePrettyMappings(final String url)
147162 {
148163 List <UIParameter > uiParams = new ArrayList <UIParameter >();
149164
150- QueryString qs = QueryString .build ("" );
151- if (url .contains ("?" ))
152- {
153- qs .addParameters (url );
154-
155- // remove own own metadata
156- qs .removeParameter ("com.ocpsoft.mappingId" );
157- }
158- Map <String , String []> queryParams = qs .getParameterMap ();
165+ Map <String , String []> queryParams = queryString .getParameterMap ();
159166
160167 List <PathParameter > pathParams = m .getPatternParser ().getPathParameters ();
161168
0 commit comments