@@ -173,7 +173,6 @@ public String getThumbnailUrl() throws ParsingException {
173173 @ Override
174174 public Description getDescription () throws ParsingException {
175175 assertPageFetched ();
176-
177176 // description with more info on links
178177 try {
179178 boolean htmlConversionRequired = false ;
@@ -184,30 +183,33 @@ public Description getDescription() throws ParsingException {
184183 String text = textHolder .getString ("text" );
185184 if (textHolder .getObject ("navigationEndpoint" ) != null ) {
186185 // The text is a link. Get the URL it points to and generate a HTML link of it
187- String internUrl = textHolder .getObject ("navigationEndpoint" ).getObject ("urlEndpoint" ).getString ("url" );
188- if (internUrl .startsWith ("/redirect?" )) {
189- // q parameter can be the first parameter
190- internUrl = internUrl .substring (10 );
191- String [] params = internUrl .split ("&" );
192- for (String param : params ) {
193- if (param .split ("=" )[0 ].equals ("q" )) {
194- String url = URLDecoder .decode (param .split ("=" )[1 ], StandardCharsets .UTF_8 .name ());
195- if (url != null && !url .isEmpty ()) {
196- descriptionBuilder .append ("<a href=\" " ).append (url ).append ("\" >" ).append (text ).append ("</a>" );
197- htmlConversionRequired = true ;
198- } else {
199- descriptionBuilder .append (text );
186+ if (textHolder .getObject ("navigationEndpoint" ).getObject ("urlEndpoint" ) != null ) {
187+ String internUrl = textHolder .getObject ("navigationEndpoint" ).getObject ("urlEndpoint" ).getString ("url" );
188+ if (internUrl .startsWith ("/redirect?" )) {
189+ // q parameter can be the first parameter
190+ internUrl = internUrl .substring (10 );
191+ String [] params = internUrl .split ("&" );
192+ for (String param : params ) {
193+ if (param .split ("=" )[0 ].equals ("q" )) {
194+ String url = URLDecoder .decode (param .split ("=" )[1 ], StandardCharsets .UTF_8 .name ());
195+ if (url != null && !url .isEmpty ()) {
196+ descriptionBuilder .append ("<a href=\" " ).append (url ).append ("\" >" ).append (text ).append ("</a>" );
197+ htmlConversionRequired = true ;
198+ } else {
199+ descriptionBuilder .append (text );
200+ }
201+ break ;
200202 }
201- break ;
202203 }
204+ } else if (internUrl .startsWith ("http" )) {
205+ descriptionBuilder .append ("<a href=\" " ).append (internUrl ).append ("\" >" ).append (text ).append ("</a>" );
206+ htmlConversionRequired = true ;
203207 }
204- } else if (internUrl .startsWith ("http" )) {
205- descriptionBuilder .append ("<a href=\" " ).append (internUrl ).append ("\" >" ).append (text ).append ("</a>" );
206- htmlConversionRequired = true ;
207- } else if (text != null ) {
208- descriptionBuilder .append (text );
208+ continue ;
209209 }
210- } else if (text != null ) {
210+ continue ;
211+ }
212+ if (text != null ) {
211213 descriptionBuilder .append (text );
212214 }
213215 }
0 commit comments