Revision 1298:4f746d8966dd .svn/pristine/0e

View differences:

.svn/pristine/0e/0e9c8f11b3db41702079f085c94dfa01133abcd9.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2013  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
require File.expand_path('../../../../../test_helper', __FILE__)
19

  
20
class PdfTest < ActiveSupport::TestCase
21
  fixtures :users, :projects, :roles, :members, :member_roles,
22
           :enabled_modules, :issues, :trackers, :attachments
23

  
24
  def test_fix_text_encoding_nil
25
    assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "UTF-8")
26
    assert_equal '', Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(nil, "ISO-8859-1")
27
  end
28

  
29
  def test_rdm_pdf_iconv_cannot_convert_ja_cp932
30
    encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
31
    utf8_txt_1  = "\xe7\x8b\x80\xe6\x85\x8b"
32
    utf8_txt_2  = "\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
33
    utf8_txt_3  = "\xe7\x8b\x80\xe7\x8b\x80\xe6\x85\x8b\xe7\x8b\x80"
34
    if utf8_txt_1.respond_to?(:force_encoding)
35
      txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
36
      txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
37
      txt_3 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
38
      assert_equal "?\x91\xd4".force_encoding("ASCII-8BIT"), txt_1
39
      assert_equal "?\x91\xd4?".force_encoding("ASCII-8BIT"), txt_2
40
      assert_equal "??\x91\xd4?".force_encoding("ASCII-8BIT"), txt_3
41
      assert_equal "ASCII-8BIT", txt_1.encoding.to_s
42
      assert_equal "ASCII-8BIT", txt_2.encoding.to_s
43
      assert_equal "ASCII-8BIT", txt_3.encoding.to_s
44
    elsif RUBY_PLATFORM == 'java'
45
      assert_equal "??",
46
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
47
      assert_equal "???",
48
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
49
      assert_equal "????",
50
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
51
    else
52
      assert_equal "???\x91\xd4",
53
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_1, encoding)
54
      assert_equal "???\x91\xd4???",
55
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_2, encoding)
56
      assert_equal "??????\x91\xd4???",
57
                   Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(utf8_txt_3, encoding)
58
    end
59
  end
60

  
61
  def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_en
62
    str1 = "Texte encod\xe9 en ISO-8859-1"
63
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
64
    str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
65
    str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
66
    txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, 'UTF-8')
67
    txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, 'UTF-8')
68
    if txt_1.respond_to?(:force_encoding)
69
      assert_equal "ASCII-8BIT", txt_1.encoding.to_s
70
      assert_equal "ASCII-8BIT", txt_2.encoding.to_s
71
    end
72
    assert_equal "Texte encod? en ISO-8859-1", txt_1
73
    assert_equal "?a?b?c?d?e test", txt_2
74
  end
75

  
76
  def test_rdm_pdf_iconv_invalid_utf8_should_be_replaced_ja
77
    str1 = "Texte encod\xe9 en ISO-8859-1"
78
    str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
79
    str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
80
    str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
81
    encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
82
    txt_1 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str1, encoding)
83
    txt_2 = Redmine::Export::PDF::RDMPdfEncoding::rdm_from_utf8(str2, encoding)
84
    if txt_1.respond_to?(:force_encoding)
85
      assert_equal "ASCII-8BIT", txt_1.encoding.to_s
86
      assert_equal "ASCII-8BIT", txt_2.encoding.to_s
87
    end
88
    assert_equal "Texte encod? en ISO-8859-1", txt_1
89
    assert_equal "?a?b?c?d?e test", txt_2
90
  end
91

  
92
  def test_attach
93
    set_fixtures_attachments_directory
94

  
95
    str2 = "\x83e\x83X\x83g"
96
    str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
97
    encoding = ( RUBY_PLATFORM == 'java' ? "SJIS" : "CP932" )
98

  
99
    a1 = Attachment.find(17)
100
    a2 = Attachment.find(19)
101

  
102
    User.current = User.find(1)
103
    assert a1.readable?
104
    assert a1.visible?
105
    assert a2.readable?
106
    assert a2.visible?
107

  
108
    aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
109
    assert_not_nil aa1
110
    assert_equal 17, aa1.id
111
    aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
112
    assert_not_nil aa2
113
    assert_equal 19, aa2.id
114

  
115
    User.current = nil
116
    assert a1.readable?
117
    assert (! a1.visible?)
118
    assert a2.readable?
119
    assert (! a2.visible?)
120

  
121
    aa1 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "Testfile.PNG", "UTF-8")
122
    assert_equal nil, aa1
123
    aa2 = Redmine::Export::PDF::RDMPdfEncoding::attach(Attachment.all, "test#{str2}.png", encoding)
124
    assert_equal nil, aa2
125

  
126
    set_tmp_attachments_directory
127
  end
128
end
.svn/pristine/0e/0e9e1072226f562ac691c9b0e43850580a4d42a6.svn-base
1
<h2><%= l(:label_spent_time) %></h2>
2

  
3
<% labelled_tabular_form_for(:time_entry, @time_entry, :url => {
4
                               :action => (@time_entry.new_record? ? 'create' : 'update'),
5
                               :id => @time_entry,
6
                               :project_id => @time_entry.project
7
                             },
8
                             :html => {:method => @time_entry.new_record? ? :post : :put}) do |f| %>
9
<%= error_messages_for 'time_entry' %>
10
<%= back_url_hidden_field_tag %>
11

  
12
<div class="box">
13
<p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
14
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
15
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
16
<p><%= f.text_field :comments, :size => 100 %></p>
17
<p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p>
18
<% @time_entry.custom_field_values.each do |value| %>
19
  <p><%= custom_field_tag_with_label :time_entry, value %></p>
20
<% end %>
21
<%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %>
22
</div>
23

  
24
<%= submit_tag l(:button_save) %>
25

  
26
<% end %>
.svn/pristine/0e/0eb716c2e3251d0a363271012989e30efeb34f17.svn-base
1
<%= form_tag(signout_path) do %>
2
  <p><%= submit_tag l(:label_logout) %></p>
3
<% end %>
.svn/pristine/0e/0ee15adcf36536c48b6695748041d2c5e43cb26a.svn-base
1
module CodeRay
2
module Scanners
3
  
4
  load :java
5
  
6
  # Scanner for Groovy.
7
  class Groovy < Java
8
    
9
    register_for :groovy
10
    
11
    # TODO: check list of keywords
12
    GROOVY_KEYWORDS = %w[
13
      as assert def in
14
    ]  # :nodoc:
15
    KEYWORDS_EXPECTING_VALUE = WordList.new.add %w[
16
      case instanceof new return throw typeof while as assert in
17
    ]  # :nodoc:
18
    GROOVY_MAGIC_VARIABLES = %w[ it ]  # :nodoc:
19
    
20
    IDENT_KIND = Java::IDENT_KIND.dup.
21
      add(GROOVY_KEYWORDS, :keyword).
22
      add(GROOVY_MAGIC_VARIABLES, :local_variable)  # :nodoc:
23
    
24
    ESCAPE = / [bfnrtv$\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} /x  # :nodoc:
25
    UNICODE_ESCAPE =  / u[a-fA-F0-9]{4} /x  # :nodoc: no 4-byte unicode chars? U[a-fA-F0-9]{8}
26
    REGEXP_ESCAPE =  / [bfnrtv\n\\'"] | x[a-fA-F0-9]{1,2} | [0-7]{1,3} | \d | [bBdDsSwW\/] /x  # :nodoc:
27
    
28
    # TODO: interpretation inside ', ", /
29
    STRING_CONTENT_PATTERN = {
30
      "'" => /(?>\\[^\\'\n]+|[^\\'\n]+)+/,
31
      '"' => /[^\\$"\n]+/,
32
      "'''" => /(?>[^\\']+|'(?!''))+/,
33
      '"""' => /(?>[^\\$"]+|"(?!""))+/,
34
      '/' => /[^\\$\/\n]+/,
35
    }  # :nodoc:
36
    
37
  protected
38
    
39
    def scan_tokens encoder, options
40
      
41
      state = :initial
42
      inline_block_stack = []
43
      inline_block_paren_depth = nil
44
      string_delimiter = nil
45
      import_clause = class_name_follows = last_token = after_def = false
46
      value_expected = true
47
      
48
      until eos?
49
        
50
        case state
51
        
52
        when :initial
53
          
54
          if match = scan(/ \s+ | \\\n /x)
55
            encoder.text_token match, :space
56
            if match.index ?\n
57
              import_clause = after_def = false
58
              value_expected = true unless value_expected
59
            end
60
            next
61
          
62
          elsif match = scan(%r! // [^\n\\]* (?: \\. [^\n\\]* )* | /\* (?: .*? \*/ | .* ) !mx)
63
            value_expected = true
64
            after_def = false
65
            encoder.text_token match, :comment
66
          
67
          elsif bol? && match = scan(/ \#!.* /x)
68
            encoder.text_token match, :doctype
69
          
70
          elsif import_clause && match = scan(/ (?!as) #{IDENT} (?: \. #{IDENT} )* (?: \.\* )? /ox)
71
            after_def = value_expected = false
72
            encoder.text_token match, :include
73
          
74
          elsif match = scan(/ #{IDENT} | \[\] /ox)
75
            kind = IDENT_KIND[match]
76
            value_expected = (kind == :keyword) && KEYWORDS_EXPECTING_VALUE[match]
77
            if last_token == '.'
78
              kind = :ident
79
            elsif class_name_follows
80
              kind = :class
81
              class_name_follows = false
82
            elsif after_def && check(/\s*[({]/)
83
              kind = :method
84
              after_def = false
85
            elsif kind == :ident && last_token != '?' && check(/:/)
86
              kind = :key
87
            else
88
              class_name_follows = true if match == 'class' || (import_clause && match == 'as')
89
              import_clause = match == 'import'
90
              after_def = true if match == 'def'
91
            end
92
            encoder.text_token match, kind
93
          
94
          elsif match = scan(/;/)
95
            import_clause = after_def = false
96
            value_expected = true
97
            encoder.text_token match, :operator
98
          
99
          elsif match = scan(/\{/)
100
            class_name_follows = after_def = false
101
            value_expected = true
102
            encoder.text_token match, :operator
103
            if !inline_block_stack.empty?
104
              inline_block_paren_depth += 1
105
            end
106
          
107
          # TODO: ~'...', ~"..." and ~/.../ style regexps
108
          elsif match = scan(/ \.\.<? | \*?\.(?!\d)@? | \.& | \?:? | [,?:(\[] | -[->] | \+\+ |
109
              && | \|\| | \*\*=? | ==?~ | <=?>? | [-+*%^~&|>=!]=? | <<<?=? | >>>?=? /x)
110
            value_expected = true
111
            value_expected = :regexp if match == '~'
112
            after_def = false
113
            encoder.text_token match, :operator
114
          
115
          elsif match = scan(/ [)\]}] /x)
116
            value_expected = after_def = false
117
            if !inline_block_stack.empty? && match == '}'
118
              inline_block_paren_depth -= 1
119
              if inline_block_paren_depth == 0  # closing brace of inline block reached
120
                encoder.text_token match, :inline_delimiter
121
                encoder.end_group :inline
122
                state, string_delimiter, inline_block_paren_depth = inline_block_stack.pop
123
                next
124
              end
125
            end
126
            encoder.text_token match, :operator
127
          
128
          elsif check(/[\d.]/)
129
            after_def = value_expected = false
130
            if match = scan(/0[xX][0-9A-Fa-f]+/)
131
              encoder.text_token match, :hex
132
            elsif match = scan(/(?>0[0-7]+)(?![89.eEfF])/)
133
              encoder.text_token match, :octal
134
            elsif match = scan(/\d+[fFdD]|\d*\.\d+(?:[eE][+-]?\d+)?[fFdD]?|\d+[eE][+-]?\d+[fFdD]?/)
135
              encoder.text_token match, :float
136
            elsif match = scan(/\d+[lLgG]?/)
137
              encoder.text_token match, :integer
138
            end
139
            
140
          elsif match = scan(/'''|"""/)
141
            after_def = value_expected = false
142
            state = :multiline_string
143
            encoder.begin_group :string
144
            string_delimiter = match
145
            encoder.text_token match, :delimiter
146
            
147
          # TODO: record.'name' syntax
148
          elsif match = scan(/["']/)
149
            after_def = value_expected = false
150
            state = match == '/' ? :regexp : :string
151
            encoder.begin_group state
152
            string_delimiter = match
153
            encoder.text_token match, :delimiter
154
            
155
          elsif value_expected && match = scan(/\//)
156
            after_def = value_expected = false
157
            encoder.begin_group :regexp
158
            state = :regexp
159
            string_delimiter = '/'
160
            encoder.text_token match, :delimiter
161
            
162
          elsif match = scan(/ @ #{IDENT} /ox)
163
            after_def = value_expected = false
164
            encoder.text_token match, :annotation
165
            
166
          elsif match = scan(/\//)
167
            after_def = false
168
            value_expected = true
169
            encoder.text_token match, :operator
170
            
171
          else
172
            encoder.text_token getch, :error
173
            
174
          end
175
          
176
        when :string, :regexp, :multiline_string
177
          if match = scan(STRING_CONTENT_PATTERN[string_delimiter])
178
            encoder.text_token match, :content
179
            
180
          elsif match = scan(state == :multiline_string ? /'''|"""/ : /["'\/]/)
181
            encoder.text_token match, :delimiter
182
            if state == :regexp
183
              # TODO: regexp modifiers? s, m, x, i?
184
              modifiers = scan(/[ix]+/)
185
              encoder.text_token modifiers, :modifier if modifiers && !modifiers.empty?
186
            end
187
            state = :string if state == :multiline_string
188
            encoder.end_group state
189
            string_delimiter = nil
190
            after_def = value_expected = false
191
            state = :initial
192
            next
193
            
194
          elsif (state == :string || state == :multiline_string) &&
195
              (match = scan(/ \\ (?: #{ESCAPE} | #{UNICODE_ESCAPE} ) /mox))
196
            if string_delimiter[0] == ?' && !(match == "\\\\" || match == "\\'")
197
              encoder.text_token match, :content
198
            else
199
              encoder.text_token match, :char
200
            end
201
          elsif state == :regexp && match = scan(/ \\ (?: #{REGEXP_ESCAPE} | #{UNICODE_ESCAPE} ) /mox)
202
            encoder.text_token match, :char
203
            
204
          elsif match = scan(/ \$ #{IDENT} /mox)
205
            encoder.begin_group :inline
206
            encoder.text_token '$', :inline_delimiter
207
            match = match[1..-1]
208
            encoder.text_token match, IDENT_KIND[match]
209
            encoder.end_group :inline
210
            next
211
          elsif match = scan(/ \$ \{ /x)
212
            encoder.begin_group :inline
213
            encoder.text_token match, :inline_delimiter
214
            inline_block_stack << [state, string_delimiter, inline_block_paren_depth]
215
            inline_block_paren_depth = 1
216
            state = :initial
217
            next
218
            
219
          elsif match = scan(/ \$ /mx)
220
            encoder.text_token match, :content
221
            
222
          elsif match = scan(/ \\. /mx)
223
            encoder.text_token match, :content  # TODO: Shouldn't this be :error?
224
            
225
          elsif match = scan(/ \\ | \n /x)
226
            encoder.end_group state
227
            encoder.text_token match, :error
228
            after_def = value_expected = false
229
            state = :initial
230
            
231
          else
232
            raise_inspect "else case \" reached; %p not handled." % peek(1), encoder
233
            
234
          end
235
          
236
        else
237
          raise_inspect 'Unknown state', encoder
238
          
239
        end
240
        
241
        last_token = match unless [:space, :comment, :doctype].include? kind
242
        
243
      end
244
      
245
      if [:multiline_string, :string, :regexp].include? state
246
        encoder.end_group state
247
      end
248
      
249
      encoder
250
    end
251
    
252
  end
253
  
254
end
255
end
.svn/pristine/0e/0ee222eff2b16f026f0f817fdf32372447c6e7e8.svn-base
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
require File.expand_path('../../test_helper', __FILE__)
19

  
20
class ProjectsTest < ActionController::IntegrationTest
21
  fixtures :projects, :users, :members
22

  
23
  def test_archive_project
24
    subproject = Project.find(1).children.first
25
    log_user("admin", "admin")
26
    get "admin/projects"
27
    assert_response :success
28
    assert_template "admin/projects"
29
    post "projects/archive", :id => 1
30
    assert_redirected_to "/admin/projects"
31
    assert !Project.find(1).active?
32

  
33
    get 'projects/1'
34
    assert_response 403
35
    get "projects/#{subproject.id}"
36
    assert_response 403
37

  
38
    post "projects/unarchive", :id => 1
39
    assert_redirected_to "/admin/projects"
40
    assert Project.find(1).active?
41
    get "projects/1"
42
    assert_response :success
43
  end
44
end

Also available in: Unified diff