Defect #20758

Ampersand+keyword in code highlighting

Added by Sergey Utkin almost 2 years ago. Updated almost 2 years ago.

Status:NewStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Third-party libraries
Target version:-
Resolution: Affected version:3.1.0

Description

I came to incorrect behavior of code highlighting in wiki-like pages if keyword begins with an ampersand.

I create a new scanner for coderay for language, which contains a directive for example "&AtServer".
And then parse the string with scan_tokens procedure:

def scan_tokens encoder, options

  state = :initial

  until eos?

    case state 

    when :initial

      if match = scan(%r! & [[:alpha:]]+ !mx)
        encoder.text_token match, :directive

      else
        encoder.text_token getch, :error
      end
    else
      raise_inspect 'Unknown state', encoder

    end

  end

  if state == :string
    encoder.end_group :string
  end

  encoder
end

And then the strange behavior starts. Testing my scanner gives correct result (&AtServer is hightlighted as :directive) but in Redmine wiki the keyword

<pre><code class="my_lang">
&AtServer
</code>


is not highlighted. However if I type ';'
<pre><code class="my_lang">
&AtServer;
</code>


the directive becomes highlighted.

ampersand_error.tar.gz - example with error (scanner, test suite, test example) (668 Bytes) Sergey Utkin, 2015-09-16 09:00

2015-09-16_10-16-55.png (1.72 KB) Sergey Utkin, 2015-09-16 09:18

History

#1 Updated by Sergey Utkin almost 2 years ago

attached an example, which looks like this

in Redmine

#3 Updated by Sergey Utkin almost 2 years ago

Environment:
  Redmine version                3.1.0.stable
  Ruby version                   2.0.0-p645 (2015-04-13) [i686-linux]
  Rails version                  4.2.3
  Environment                    production
  Database adapter               Mysql2
SCM:
  Subversion                     1.8.13
  Git                            1.9.5
  Filesystem                     
Redmine plugins:
  a_common_libs                  1.1.5
  computed_custom_field          0.0.2
  custom_menu                    1.5.0
  extra_queries                  2.0.0
  global_roles                   2.0.0
  redmine_checklists             3.1.1
  redmine_codebutton             0.1.0
  redmine_dashboard              2.7.0
  redmine_dmsf                   1.5.3
  redmine_email_fetcher          0.3.1
  redmine_my_page                0.1.6
  redmine_tweaks                 0.5.5
  rm_user_mentions               1.0.0
  single_auth                    2.0.0
  under_construction             2.0.0
  unread_issues                  1.5.0
  usability                      1.3.0

Also available in: Atom PDF