Bug 30297 - fmt strips quotes when using parameter
Summary: fmt strips quotes when using parameter
Status: RESOLVED INVALID
Alias: None
Product: Taglibs
Classification: Unclassified
Component: Standard Taglib (show other bugs)
Version: 1.0.5
Hardware: Other other
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-23 15:32 UTC by Gael Marziou
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gael Marziou 2004-07-23 15:32:41 UTC
Hello,

I have a bundle containing one key:

feedback2 = Rock'n Roll

It displays correctly as "Rock'n Roll" when using this:

        <fmt:message key="feedback2" />

While the single quote got stripped out "Rockn Roll" when I use this:

        <fmt:message key="feedback2" >
            <fmt:param />
        </fmt:message>

Thanks for your help,

Gael
Comment 1 Kris Schneider 2004-07-23 17:10:31 UTC
It may seem surprising, but it works as defined in the spec. What's happening is
that the existence of a format parameter is causing the tag to use MessageFormat
to process the message. Check out sections 8.8 <fmt:message> and 8.9 <fmt:param>
of the spec, as well as the JavaDoc for java.text.MessageFormat.

Here's some test code to illustrate the effect:

import java.text.*;
import java.util.*;

public class FmtTest {

    public static class Messages extends ListResourceBundle {
        private static final Object[][] CONTENTS = {
            {"feedback2",            "Rock'n Roll"},
            {"feedback2-xtra-quote", "Rock''n Roll"}
        };

        protected Object[][] getContents() {
            return CONTENTS;
        }
    }

    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("FmtTest$Messages");
        String feedback2 = bundle.getString("feedback2");
        String feedback2XtraQuote = bundle.getString("feedback2-xtra-quote");

        System.out.println("feedback2:");
        System.out.println(feedback2);
        System.out.println(MessageFormat.format(feedback2, null));

        System.out.println();
        System.out.println("feedback2-xtra-quote:");
        System.out.println(feedback2XtraQuote);
        System.out.println(MessageFormat.format(feedback2XtraQuote, null));
    }
}

This will output:

feedback2:
Rock'n Roll
Rockn Roll

feedback2-xtra-quote:
Rock''n Roll
Rock'n Roll
Comment 2 Gael Marziou 2004-07-23 18:18:23 UTC
Thanks for your explanation, I think it should be a FAQ and it's too bad that 
the spec did go this way.
It's a nightmare for localizers and for developers because the only suggestion 
in the MessageFormat javadoc is to use comments in resource bundle source 
files to indicate which strings will be processed by MessageFormat. 
What about evolutions? It's obvious that some parameters will be added during 
the life of an application and we should rely only on comments to avoid 
problems?

Anyway, which better alternative do I have:
- write my own tag to fix this "correct" behavior
- always use <param> even if empty

Any suggestion is welcome.