Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update default for favorPathExtension to match Javadoc and as intended for 5.3 #26119

Closed
mwftapi opened this issue Nov 19, 2020 · 2 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@mwftapi
Copy link

mwftapi commented Nov 19, 2020

Affected Version: Spring Web 5.3.1.

Deprecation note on ContentNegotiationManagerFactoryBean:setFavorPathExtension(boolean) is misleading.

/**
* Whether the path extension in the URL path should be used to determine
* the requested media type.
* <p>By default this is set to {@code false} in which case path extensions
* have no impact on content negotiation.
* @deprecated as of 5.2.4. See class-level note on the deprecation of path
* extension config options. As there is no replacement for this method,
* in 5.2.x it is necessary to set it to {@code false}. In 5.3 the default
* changes to {@code false} and use of this property becomes unnecessary.
*/
@Deprecated
public void setFavorPathExtension(boolean favorPathExtension) {
this.favorPathExtension = favorPathExtension;
}

It states that As there is no replacement for this method, in 5.2.x it is necessary to set it to {@code false}. In 5.3 the default changes to {@code false} and use of this property becomes unnecessary.

But the default value of favorPathExtension still is true.

If the property is not used, path extension will be favored indicating that a call to setFavorPathExtension(false) is still necessary, contrary to the deprecation note.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 19, 2020
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 19, 2020

I believe the intent was to turn off path extensions completely in 5.3, both for content-type and for suffix pattern matching. This is also based on the fact that a deprecation on a method does not mean much if you must use it to achieve the recommended configuration. I'll take a closer look at correcting this in 5.3.2.

@rstoyanchev rstoyanchev self-assigned this Nov 19, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 19, 2020
@rstoyanchev rstoyanchev added this to the 5.3.2 milestone Nov 19, 2020
@rstoyanchev rstoyanchev changed the title Deprecation Note On ContentNegotiationManagerFactoryBean Is Misleading Deprecation note on setFavorPathExtension does not match actual default Nov 19, 2020
@rstoyanchev rstoyanchev changed the title Deprecation note on setFavorPathExtension does not match actual default Update default for favorPathExtension to match the Javadoc and as was intended for 5.3 Nov 24, 2020
@rstoyanchev rstoyanchev changed the title Update default for favorPathExtension to match the Javadoc and as was intended for 5.3 Update default for favorPathExtension to match Javadoc and as intended for 5.3 Nov 24, 2020
@rstoyanchev
Copy link
Contributor

I have changed the default setting of favorPathExtension so that now both path extensions are not checked and suffix pattern matching is not used by default.

For applications that need to revert back for the time being:

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.favorPathExtension(true);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer
            // ...
            .setUseSuffixPatternMatch(true);
    }
}
<mvc:annotation-driven content-negotiation-manager="mvcContentNegotiationManager" />
    <mvc:path-matching suffix-pattern="true"/>
</mvc:annotation-driven>

<bean id="mvcContentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
    <property name="favorPathExtension" value="true"/>
</bean>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants